I am working on the Laravel Validation code. In my code, I used the radio button for three options like approve, reject, and return. In the Remarks textbox, validation depends on the Radio button values. Without choosing any options, the validation is working fine, like "Please choose any one." If I choose the Approve option, then the Remarks textbox validation shows an error like "Please enter remarks for your approval". If I choose the Reject Option, it shows an error like "Please enter remarks for rejection."
<input type="radio" id="approve" name="radiooption" value="-1">
<input type="radio" id="reject" name="radiooption" value="R">
<input type="radio" id="return" name="radiooption" value="A">
<input type="text" value = "Remarks" name = "remarks" >
$validated = $request->validate([
'radiooption' => ['required'],
'remarks' => ['required_if:radiooption',-1,'A','R']
]
[
'radiooption.required' => 'Please choose one of the action.',
'remarks.required_if' => 'Please enter reason(s) to applicant :values',
]
Above is not working, It shows error like Validation rule required_if requires at least 2 parameters. Please support me to solve that issue
id="radiooption"3 times, but ids need to be unique, or useclass="radiooption"instead. No effect on your current issue (which is a syntax error on usage ofrequired_if: laravel.com/docs/10.x/validation#rule-required-if), but if you ever tried to targetdocument.getElementById('radiooption'), you'd run into issues.