我如何验证/发布编辑类型为表单编辑中的 jqgrid 选择的列
How can I validate/post col with edit type as select in jqgrid in form edit
我想在保存时将我的表单数据(包含 3 个选择(选择)字段)发送到服务器。
我该怎么做?我无法在任何函数中检索它们的值:
beforeSubmit
、onclickSubmit
和beforeCheckValues
。
colNames:['Role','Department','Employee','City','employeeId','deptId'],
colModel:[
{name:"role", index:"role", width:200,editable:true, edittype:"select",formoptions:{rowpos:2},editoptions:{
style:"width:95%" ,
dataInit: function (elem) {
var optionBlank = document.createElement('option');
optionBlank.text = "Select Role" ;
optionBlank.value = "Select Role" ;
elem.add(optionBlank);
$(elem).addClass('roleChosen');
$(elem).chosen({search_contains:true});
}
}
},
{name:"dept", index:"dept", width:200,editable:true, edittype:"select",formoptions:{rowpos:1},editrules:{required:true},editoptions:{
style:"width:95%",
dataInit: function (elem) {
$.ajax({
url: "/getDeptNames.json",
dataType: "json",
type:"POST",
async:false,
success: function(data, status){
var optionBlank = document.createElement('option');
optionBlank.text = "Select Department" ;
optionBlank.value = "Select Department" ;
elem.add(optionBlank);
for(var i = 0; i<data.length; i++) {
var option = document.createElement('option');
option.innerHTML = "<b>" +data[i].name + "</b>";
option.value =data[i].deptId;
elem.add(option);
}
$(elem).addClass('deptNameChosen');
$(elem).chosen({search_contains:true});
}
});
},
dataEvents: [
{ type: 'change', fn: function(e) {
getRolesFromDept($('.deptNameChosen :selected').val()); //will populate role column
},
}
]
}
},
{name:"employee", index:"employee", width:150,editable:true,editrules:{required:true,custom: true,custom_func: empVldtnCheck},editoptions:{
style:"width:95%",
dataInit: function (elem) {
var autocompleteSource = function(request, response,term) {
$.ajax({
url: "empAutoComplete.json",
contentType: "application/json; charset=utf-8",
dataType: "json",
type: "GET",
async:false,
data : {
featureClass : "P",
style : "full",
name_startsWith : request.term
},
success : function(data, status) {
response($.map(data.details, function(item) {
return {
label : item.employeeName,
value : item.employeeName,
employeeId : item.employeeId
};
}));
},
error: function (res, status) {
alert(res.status+" : "+res.statusText+". Status: "+status);
}
});//END AJAX
};
$(elem).autocomplete({
autoFocus: true,
source: autocompleteSource,
position: { collision: "flip" },
minLength: 3,
select: function (a, b) {
getCityForEmployee(b.item.employeeId);
}
});//END AUOTOCOMPLETE
}
},formatter:function(cellValue,options,rowObject){
return "<span class='hyperLink'>" +"<a target='_blank' href="+ rowObject.employeeURL +"?employee="+ encodeURI(rowObject.employee) +">"+rowObject.employee+"</a>" + "</span>";
}
},
{name:"city", index:"city",editable:true,edittype:"select",editrules:{required:true}, editoptions : {
style:"width:95%",
multiple:true,
dataInit: function (elem) {
$(elem).addClass('cityChosen');
var optionBlank = document.createElement('option');
optionBlank.text = "Select Module" ;
optionBlank.value = "Select Module" ;
elem.add(optionBlank);
$(elem).chosen({search_contains:true});
}//END Dataint
}, width:200},
{name:"employeeId",editable:false, index:"employeeId", hidden:true},
{name:"deptId", index:"deptId",editable:false, hidden:true}
]
postData 仅正确显示员工列数据,甚至不显示部门和角色的任何数据,仅显示城市列的值。
如果需要验证数据,应首先尝试使用editrules: {custom: true, custom_func: ...}
请参阅文档。
像beforeSubmit
这样的回调包含postdata
(第一个参数)。它是对象,哪些属性是已编辑的列的名称。属性的值是输入用户的值。所以你只需要检查postdata
.
已更新:如果您在beforeSubmit
中有错误的postdata
,则应验证编辑对话框的<input>
和<select>
字段的 ID 是否具有与colModel
属性name
值相同的值。我建议您注释dataInit
代码的临时部分。在加载 select 的动态选项时,建议使用 dataUrl
,建议对静态值使用 value
,如role
列中所示。
我同时使用了编辑选项的"value"和"dataInit"以及edittype:"select"来解决这个问题。值:用于给出默认值dataInit :初始化为选定的自动完成/选择。
-
正确的方法
{名称:"城市", 索引:"城市",可编辑:真,编辑类型:"选择",编辑规则:{必需:真}, 编辑选项 : { 样式:"宽度:95%", 值:{"选择城市":"选择城市"},
dataInit: function (elem) { $(elem).addClass('cityChosen'); $(elem).chosen({search_contains:true}); }//END Dataint }
-
错误的方法
{name:"city", index:"city",editable:true,edittype:"select",editrules:{required:true}, 编辑选项 : { 样式:"宽度:95%",
dataInit: function (elem) { var optionBlank = document.createElement('option'); 选项空白文本 = "选择城市" ; 选项空白值 = "选择城市" ; elem.add(optionBlank);$(elem).addClass('cityChosen'); $(elem).chosen({search_contains:true}); }//END Dataint }
第二个将销毁选择元素的ID。
- 基于数据类型的编辑框的汇总列表
- 在plone 5中将自定义的灵活性内容类型插入到tinymce编辑器中
- 我如何验证/发布编辑类型为表单编辑中的 jqgrid 选择的列
- 内容可编辑-根据类型从一个跨度到另一个跨度克隆文本
- 在设置 IIS Express 以识别 JSON 文件类型后 - VS 是否可以调用除纯文本之外的更好的编辑器
- 使用编辑类型:基于所选值选择时,如何在 JQGrail 中启用或禁用子网格
- j可编辑输入类型日期
- CKEditor 未捕获的类型错误:无法在具有多个编辑器的 EmberJS 单页应用程序中调用 null 的“不可选择”
- 如何通过将值传递给输入类型来编辑 html 表值
- 除了在 AngularJS 中为每种类型的编辑创建一个函数之外,有没有更好的方法可以在页面上拥有可编辑的元素
- 使用 django-froala-editor,编辑器在管理页面中工作不会在帖子页面中工作吗?未捕获的类型错误: $(.
- 未捕获的类型错误: $(..).froala编辑器不是一个函数//解决方案被找到,但不确定如何使用它
- Jqgrid编辑类型:"选择“;事件
- 未捕获的类型错误:Object[Object Object]没有方法'可编辑'
- 如何避免在asp中在一个剑道网格中使用两种类型的编辑时创建不需要的弹出窗口
- 我可以't编辑我的<输入类型=“;文件“>标签
- 如何在按下按钮时创建不可编辑的类型(如标签)
- CK编辑器-未捕获类型错误:无法读取属性'的空在Chrome
- 为什么“;& lt;输入类型=“number"/比;“;无法在angular 1.4.6的chrome中编辑
- 如何从类型为'select'? (x-可编辑)(laravel 5.2)