Enhance TagsInput validation: ensure at least one item is required for non-empty arrays; improve setting value handling in Retrieved event
This commit is contained in:
@@ -98,11 +98,17 @@ class FilamentInput
|
||||
->hintColor('primary')
|
||||
->helperText($setting->description ?? '');
|
||||
|
||||
// For required TagsInput, we need to validate the array has at least one item
|
||||
// Filament's required() alone considers empty arrays as "filled"
|
||||
// For required TagsInput, validate that array has at least one item
|
||||
// Standard 'required' rule considers empty arrays as valid
|
||||
if ($setting->required ?? false) {
|
||||
$input->required()
|
||||
->rules(['array', 'min:1']);
|
||||
->rule(function () {
|
||||
return function (string $attribute, $value, \Closure $fail) {
|
||||
if (!is_array($value) || empty($value)) {
|
||||
$fail('The :attribute field must have at least 1 items.');
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
return $input;
|
||||
|
||||
Reference in New Issue
Block a user