-
Notifications
You must be signed in to change notification settings - Fork 11k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Validation using required_with behaves in a strange way #17211
Comments
Please provide the data that fails to pass validation. |
It's an ajax call in which I pass many fields, these are the ones of interest:
|
The problem is that you assume the rest of the rules won't be applied if the field is empty but that's not true, the condition only falls on
If
this will cause the integer check to run only if volume_max is not empty. This is not an issue with the framework so i'll close the issue, but please feel free to ping me for further clarification. |
Ok, I see, and will look into it later to make it work with my app. But, as you said:
isn't this behaviour in contradiction with this merged pull request? #15089 |
It'll skip validation if a required rule fails, not skipped. This is a confusing point yes, might worth mentioning in the docs, will take care of that :) |
Has this issue been updated in the documentation? |
I'm seeing this same issue using required_without_all, is there a fix? 'gnar'=>'required_without_all,foo,bar|min:1between:0.01,99999999.99', foo and bar are both set, gnar is null, but gnar is failing as "gnar min must be at least 1" |
This behavior might have good technical reasons, but it is IMHO counter-intuitive. Just spent at least an hour to debug, find this issue and workaround this issue. @stevevg's example reads: // if volume_min is given, then this field is required. It should be an integer, greater than volume_min
'volume_max' => 'required_with:volume_min|integer|greater_than_field:volume_min' It does not read // if volume_min is given, then this field is required.
// It is nullable. And even if it's null then it should be an integer, greater than volume_min
'volume_max' => 'required_with:volume_min|integer|greater_than_field:volume_min' Hm.. thinking about it.. Would it be possible to specify it like (adding
|
Any updates? |
Description:
Using a validation rule of type:
'field1' => 'required_with:field2'
fails even iffield2
is present but empty. Is this the expected behavior? I'm quite sure this did not happen in 5.2Steps To Reproduce:
I've tried with this rules in my
CustomRequest
file:but I receive the error
volume_min must be an integer, volume_min must be at least 1
andvolume_max must be an integer, volume_max must be greater than volume_min
, even if both fields are POSTed (actually with _method: PUT) empty.I've currently fixed using a method based on #17032 (comment) but I'm not sure if this is the desired behavior of the validator.
This is my fix:
The text was updated successfully, but these errors were encountered: