我正在尝试启用当前已选中的复选框并将其存储到数组中。
到目前为止,这是我的表单代码:
<?php $index = 0; ?>
@foreach($dayOfWeek as $key => $day )
<div class="parttime">
<div class="row">
<div class="col-xs-2">
<div class="form-group">
{!! Form::text('parttimeAvailabilities['.$index.'][day]',$day, ['class' => 'form-control','disabled'])!!}
{!! Form::hidden('parttimeAvailabilities['.$index.'][day]',$key, ['class' => 'form-control'])!!}
{!! Form::hidden('parttimeAvailabilities['.$index.'][id]',null) !!}
</div>
</div>
<div class="col-xs-2">
<div class="form-group">
{!! Form::text('parttimeAvailabilities['.$index.'][start_time]', null, ['class' => 'form-control start_time','placeholder' => 'Start time', 'disabled'])!!}
</div>
</div>
<div class="col-xs-2">
<div class="form-group">
{!! Form::text('parttimeAvailabilities['.$index.'][end_time]', null, ['class' => 'form-control end_time','placeholder' => 'End time', 'disabled'])!!}
</div>
</div>
<div class="col-xs-2">
<div class="form-group">
{!! Form::text('parttimeAvailabilities['.$index.'][hours]', null, ['id' => 'hours','class' => 'form-control','readonly'])!!}
</div>
</div>
<div class="col-xs-2 text-center">
<div class="form-group">
{!! Form::checkbox('parttimeAvailabilities['.$index.'][available]')!!}
</div>
</div>
</div>
</div>
<?php $index++; ?>
@endforeach
这是我到目前为止的jQuery代码:
$('div.parttime').each(function(index) {
var checkbox = $('input[name="parttimeAvailabilities['+index+'][available]"]');
var startbox = $('select[name="parttimeAvailabilities['+index+'][start_time]"]');
var endbox = $('select[name="parttimeAvailabilities['+index+'][end_time]"]');
$(startbox).prop("enable", $(checkbox).prop('checked'));
$(endbox).prop("enable", $(checkbox).prop('checked'));
$('#driverForm').bootstrapValidator('addField', startbox, {
validators: {
notEmpty: {
message: 'The start time is required and cannot be empty'
},
}
});
$('#driverForm').bootstrapValidator('addField', endbox, {
validators: {
notEmpty: {
message: 'The end time is required and cannot be empty'
},
}
});
$(checkbox).on('click', function(e) {
$(selectbox).select2('val', '');
var bootstrapValidator = $('#driverForm').data('bootstrapValidator');
bootstrapValidator.enableFieldValidators(startbox, !$(checkbox).prop('checked'));
bootstrapValidator.enableFieldValidators(endbox, !$(checkbox).prop('checked'));
$(startbox).prop("enable", $(checkbox).prop('checked'));
$(endbox).prop("enable", $(checkbox).prop('checked'));
});
});
它会抛出此错误:
bootstrapValidator.js:1521未捕获TypeError:无法读取属性 未定义的'验证者'
任何想法?