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:
2026-03-12 18:09:02 -04:00
parent 7ae257dede
commit 0f36dba867
2 changed files with 15 additions and 5 deletions

View File

@@ -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;