[bug] unexpected order of validation rules applied
jdoubleu opened this issue · 1 comments
When it comes to validation, I find the order in which the rules are applied unexpected and unintuitive.
Take this for example:
$rules = [
'email' => 'required|email'
];
tr_validator($rules, tr_request()->getFields());
The email
field, when left-blank, will report something like "must be an email address". I would expect the required
rule to be checked first, so that the message would be something like "this field is required".
As far as I checked in the Validator
, this is due to the fact, that errors raised by the following rules overwrite previous errors (see https://github.com/TypeRocket/core/blob/main/src/Utility/Validator.php#L532).
In my opinion, following rules, email
in this case, do not need to be validated, if previous rules, required
in this case, already failed. Or if they are, still keep the first error message and display that first. Otherwise one has to flip the order of the rules around. This would be in contrast to the examples in the documentation (e.g. https://typerocket.com/docs/v5/validator/#section-about-validation).
Hey @jdoubleu
These issues are addressed in the latest patch alongside a few new validation rule features.
https://github.com/TypeRocket/core/releases/tag/v5.0.80
Thanks,
Kevin