This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

cryonos
cryonos

Hello everyone,

In my form validation I use different required_if and it's working when I test if a boolan value is 1:

'has_bill' => ['required', 'boolean'],
'billing_vat' => ['required_if:has_bill,1'],

In this case I have no errors if I don't fill billing_vat when has_bill is false (0), But it doesn't work if I do this:

'has_bill' => ['required', 'boolean'],
'billing_type' => ['required_if:has_bill,1', 'boolean'],
'billing_first_name' => ['required_if:has_bill,1,billing_type,0'],

if this case, if billing_type is set to 1 , the validation fails on billing_first_name requirement, even if it shouldn't! (billing_first_name is required only if the billing_type is '0')

Any idea on how to resolve this?

Thanks

Last updated

mjauvin
mjauvin

Did you try with true and false like this:

'billing_type' => ['required_if:has_bill,true', 'boolean'],
'billing_first_name' => ['required_if:billing_type,false'],

?

cryonos
cryonos

Yes but it did not worked. I tried again changing all the required_if test values with true/false instead of 1/0, and if I let the required fields empty, the validation returns no errors!

cryonos
cryonos

The problem comes when the required_if tests 2 different booleans:

Working:

'billing_type' => ['required_if:has_bill,1', 'boolean'],
'billing_first_name' => ['required_if:billing_type,0'],

Not working:

'billing_type' => ['required_if:has_bill,1', 'boolean'],
'billing_first_name' => ['required_if:has_bill,1,billing_type,0'],

Last updated

mjauvin
mjauvin

Open an issue on October's github repo regarding this and link it here.

Thanks.

Last updated

cryonos
cryonos

Sorry for the delay, I opened the issue:

https://github.com/octobercms/october/issues/5535

thanks!

1-6 of 6

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.