乐趣区

00023layui表单有checkradioswitch未选中时值不提交的解决

表单字段:

<div class="layui-form-item layui-form-item-45" >
   <label class="layui-form-label"> 是否需要外勤 </label>
   <div class="layui-input-block">
      <input type="checkbox" name="isNeedOut" lay-filter="form-switch" lay-skin="switch" lay-text="是 | 否">
   </div>
</div>
<div class="layui-form-item layui-form-item-45" >
   <label class="layui-form-label"> 是否收费 </label>
   <div class="layui-input-block">
      <input type="checkbox" name="isCost" lay-filter="form-switch" lay-skin="switch" lay-text="是 | 否">
   </div>
</div>
<div class="layui-form-item layui-form-item-45" >
   <label class="layui-form-label"> 是否延期 </label>
   <div class="layui-input-block">
      <input type="checkbox" name="isDelay" lay-filter="form-switch" lay-skin="switch" lay-text="是 | 否">
   </div>
</div>

提交:

var dialog = layer.open({
             type: 2
             ,title: '添加任务单'
             ,content: '../task/taskForm.jsp'
             ,maxmin: true
             ,area: layui.setter.area
             ,btn: ['确定', '取消']
             ,btnAlign: 'c'
             ,yes: function(index, layero){var iframeWindow = window['layui-layer-iframe'+ index]
                     ,submit = layero.find('iframe').contents().find("#taskForm-submit");
                 iframeWindow.layui.form.on('submit(taskForm-submit)', function(data){
                     var field = data.field;
                     field.taskSource = 1;// 合同事项
field.isUrgent = field.isUrgent?field.isUrgent:false;
                     field.isNeedOut = field.isNeedOut?field.isNeedOut:false;
                     field.isCost = field.isCost?field.isCost:false;
                     field.isDelay = field.isDelay?field.isDelay:false;
                     var rtn = admin.syncReq(ctx+"/task/task/add",field);
                     if(rtn && rtn.code==0){layer.msg('操作成功');
                         active.reload();
                         layer.close(index);
                     }else{layer.msg('操作失败');
                     }
                 });
                 submit.trigger('click');
             }
         });
         layer.full(dialog)

像这样:

field.isUrgent = field.isUrgent?field.isUrgent:false;

无值是传 false 到后台即可。

退出移动版