Issue using "required_if" validation rule in form builder

Issue using "required_if" validation rule in form builder

kiltedup -
1 year ago

Hi,

I think this is a Laravel issue but posting here to see if anyone has encountered this and can suggest a solution. I had a form with a bunch of custom validation. This was working on Pyro 3.0 but since the site was upgraded to 3.3 it has stopped working.

Issue is that if a 'required_if' rule is used, any subsequent rules are still processed. Whereas before they would be skipped. Example rules on two fields :

Before - if my sosParent field was set to 'Yes' then the 'digits' rule on sosTel was ignored. But now it is still enforced. This sosTel field only appears when sosParent is 'No' so the error is never shown.

If that makes sense, any suggestions on how to ignore the second rule ????

Thanks

Dave

ryanthompson -
1 year ago

This might be because of the nullable rule introduced in Laravel 5.3..

kiltedup -
1 year ago

It's the sosTel that's the issue. sosParent is set to Yes so sosTel is NOT required, but the sosTel still needs 11 digits to validate
Just seen the 'nullable' stuff :
So the rule : required_if:sosParent,No|nullable|digits:11 appears to do the trick .... I think

ryanthompson -
1 year ago

mattcdavis1 -
1 year ago

@ryanthompson - so is modifying the core the only way to get required_with/required_if to work? I'm having the same issue due to nullable being the first rule and my formBuilder rules just getting merged into that.