I have 3 input fields (reservationdate, starttime, endtime) and 1 checkbox (holeday). If the checkbox clicked I do not need starttime and endtime. On the other hand starttime and endtime is required. What can I do to solve this task?
I tried in Laravel the required_if validation-function. But I'm certainly using it wrong
ReservationController store:
$data = $request->validate([
'userid' => 'required|numeric',
'vehicleid' => 'required|numeric',
'budgetid' => 'required|numeric',
'reservationdate' => 'required|date',
'starttime' => 'required_if:holeday,on|date_format:H:i|before_or_equal:endtime',
'endtime' => 'date_format:H:i',
'holeday' => 'boolean'
]);
index.blade.php (only the checkbox)
<div class="input-field col s2">
<label>
<input type="checkbox" name="holeday" class="filled-in" />
<span>Hole Day</span>
</label>
</div>
If the checkbox is checked I get the error-message "The starttime field is required when holeday is on." but in this case I need no error. Hey user it is OK. I don´t need a starttime or endtime. Your clicked the holeday.
Aucun commentaire:
Enregistrer un commentaire