00023-layui表单有check、radio、switch,未选中时值不提交的解决

表单字段:

提交:

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 到后台即可。

你可能感兴趣的:(layui)