我有一个带有这些输入的注册表:选项,您可以用复选框选中,用附加选项选择。两者都使用foreach。
我曾尝试使用jquery使extraoption select成为必需,但现在当我选中其中一个复选框时,它使all select成为必需。如果我取消选中所有复选框,选择仍然是必需的。
滑动分页
if(this.checked){
$('.extraoption').attr('required', 'True');
}
else{
$('.extraoption').attr('required', 'False');
}
<label>Options</label><br>
@foreach($option_array as $option)
<div>
<input type="checkbox" class="option" id="option_{{ $option->exa_id }}" name="option_{{ $option->exa_id }}" value="{{ $option->exa_id }}" {{ isset($cache) ? (isset($cache['option_' . $option->exa_id]) ? 'checked' : '') : (old() ? (old('option_' . $option->exa_id) ? 'checked' : '') : ($registration ? (in_array($option->exa_id, $registration_options) ? 'checked' : '') : '')) }} >
<input type="hidden" value="{{ $option->exa_prijs }}" class="option_prijs_{{ $option->exa_id }}">
<label>{{ $option->exa_naam }}</label> <label class="exa_prijs"> â¬{{ $option->exa_prijs }} </label>
</div>
<select name="extraoptions_{{ $option->exa_id }}" class="form-control extraoption">
<option></option>
@foreach($option->extraoptions as $extraoption)
<option value="{{ $extraoption->eos_id }}" {{ ($inschrijving ? (in_array($extraoption->eos_id, $inschrijving_options_extra) ? 'selected' : '') : '') }}>{{ $extraoption->eos_name }}</option>
@endforeach
</select>
<br>
@endforeach