validation ->in() rule is not executed when checking against an empty array
hey guys,
we just encountered a problem with the ->in() rule on the form builder.
we try to validate user input against (in some cases) an empty array. we expected the rule to fail, since the user input is obviously not present in an empty array.
after some research in the implementation, we've found this line:
https://github.com/filamentphp/filament/blob/3.x/packages/forms/src/Components/Concerns/CanBeValidated.php#L227
saying that the >in() rule is only validated, if the array to validate against is not empty.
does anybody know why the rule is implemented like this? for some special reason?
please note that the underlying laravel's in rule fails against an empty array and since there is no information in the docs about this, we expected the filament rule to work in the same way.
cheers
GitHub
filament/packages/forms/src/Components/Concerns/CanBeValidated.php ...
A collection of beautiful full-stack components for Laravel. The perfect starting point for your next app. Using Livewire, Alpine.js and Tailwind CSS. - filamentphp/filament
3 Replies
I guess I would always combine it with with a
min
rule.
@Dan Harrin Do you have an explanation here?$values can be a string
we are using that to check that the string is not empty
the reason we do it is so that you can conditionally disable the rule if you want by passing null
we should change that check so it uses
=== null
instead of filled()
you're welcome to PRthanks for your explanation π will create a PR