Skip to content

Commit f27d7b6

Browse files
committed
Merge branch 'feat/conditional-fields' of github.com:backstagephp/fields into feat/conditional-fields
2 parents 5eacd38 + 920eb66 commit f27d7b6

File tree

5 files changed

+73
-5
lines changed

5 files changed

+73
-5
lines changed

src/Fields/FormSchemas/BasicSettingsSchema.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,18 @@ public static function make(): array
3333
->label(__('Hint color'))
3434
->visible(function (Forms\Get $get): bool {
3535
$hint = $get('config.hint');
36+
3637
return ! empty(trim($hint));
3738
}),
3839
Forms\Components\TextInput::make('config.hintIcon')
3940
->label(__('Hint icon'))
4041
->placeholder('heroicon-m-')
4142
->visible(function (Forms\Get $get): bool {
4243
$hint = $get('config.hint');
44+
4345
return ! empty(trim($hint));
4446
}),
4547
]),
4648
];
4749
}
48-
}
50+
}

src/Fields/FormSchemas/ValidationRulesSchema.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ public static function make(): array
119119
$excludeUlid = $record->ulid;
120120
}
121121
}
122+
122123
return FieldOptionsHelper::getFieldOptions($livewire, $excludeUlid);
123124
})
124125
->visible(fn (Forms\Get $get): bool => in_array($get('type'), ['different', 'same', 'prohibited_if', 'prohibited_unless', 'prohibits', 'required_if', 'required_unless', 'required_if_accepted', 'greater_than', 'greater_than_or_equal', 'less_than', 'less_than_or_equal'])),
@@ -136,6 +137,7 @@ public static function make(): array
136137
$excludeUlid = $record->ulid;
137138
}
138139
}
140+
139141
return FieldOptionsHelper::getFieldOptions($livewire, $excludeUlid);
140142
})
141143
->visible(fn (Forms\Get $get): bool => in_array($get('type'), ['required_with', 'required_with_all', 'required_without', 'required_without_all'])),
@@ -165,4 +167,4 @@ public static function make(): array
165167
]),
166168
];
167169
}
168-
}
170+
}

src/Fields/Helpers/FieldOptionsHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,4 @@ public static function getFieldNamesFromUlids(array $ulids, Field $currentField)
6565

6666
return $fieldNames;
6767
}
68-
}
68+
}

src/Fields/Logic/ConditionalLogicApplier.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,24 +31,28 @@ public static function applyConditionalLogic($input, ?Field $field = null): mixe
3131
$input->visible(
3232
fn (Forms\Get $get): bool => self::evaluateCondition($get($conditionalFieldName), $operator, $value)
3333
);
34+
3435
break;
3536

3637
case 'hide':
3738
$input->visible(
3839
fn (Forms\Get $get): bool => ! self::evaluateCondition($get($conditionalFieldName), $operator, $value)
3940
);
41+
4042
break;
4143

4244
case 'required':
4345
$input->required(
4446
fn (Forms\Get $get): bool => self::evaluateCondition($get($conditionalFieldName), $operator, $value)
4547
);
48+
4649
break;
4750

4851
case 'not_required':
4952
$input->required(
5053
fn (Forms\Get $get): bool => ! self::evaluateCondition($get($conditionalFieldName), $operator, $value)
5154
);
55+
5256
break;
5357
}
5458

@@ -83,6 +87,7 @@ public static function applyConditionalValidation($input, ?Field $field = null):
8387
} elseif ($operator === 'is_not_empty') {
8488
$input->requiredIf($conditionalFieldName, '');
8589
}
90+
8691
break;
8792

8893
case 'not_required':
@@ -123,4 +128,4 @@ protected static function evaluateCondition($fieldValue, string $operator, $expe
123128
return false;
124129
}
125130
}
126-
}
131+
}

0 commit comments

Comments
 (0)