What about not even POSTing the data in the first place? So when that checkbox is selected I remove it from the DOM then use sometimes? Any reason that's bad?
Oct 14, 2019
5
Level 3
Conditional validation on arrays
I have a Form Request that has some validation rules conditionally met on a checkbox (main_dealer) being checked:
public function rules()
{
return [
'bid_lines.*.description' => ['required', 'min:3', 'max:100', 'string'],
'bid_lines.*.brand' => ['required_without:bid_lines.*.main_dealer', 'in:genuine,oe,aftermarket'],
];
}
The above required_without code works - the brand select input isn't required if the main_dealer checkbox is checked.
The problem is that the in: condition is still being triggered even if it's not required, so is failing. Can someone help me figure this out?
Level 73
@johncarter I don't think it is bad but it is extra work. Why not allowing it to be nullable instead?
What kind of data does it contain when the main_dealer checkbox is checked?
1 like
Please or to participate in this conversation.