在 colModel 中,我有一个custom_func: myFunc()
测试输入到 jqGrid 本机添加或编辑模式表单的文本字段中的整数值是否尚未在loadonce:true
选项中设置的网格中可见的少数行中使用。在单击模态表单提交按钮之前不会执行它的方式,custom_func:
但我希望在焦点输出(或模糊?)时测试模态表单文本字段。有没有办法做到这一点?我已经尝试按照afterShowForm:
选项中显示的方式执行此操作,并且它可以正常工作,但是错误消息和停止与单击提交按钮时不同,有没有办法从以下位置进行聚焦/模糊custom_func: myFunc()
?
下面显示了 colModel 片段,然后是自定义函数,然后是我尝试在afterFormShow: function()
Add modal 表单中使用 focusout。
//colModel
...},
{name: 'ezyid', index: 'ezyid', width: 60, align: "center", editable: true,
formoptions: { rowpos: 1,
colpos: 1,
label: "Ezy ID",
elmprefix: "(*) "
},
editrules: {
custom: true,
custom_func: chkDuplicateEzyids, //custom function
required: true
}
},
colModel 自定义函数:
function chkDuplicateEzyids(value, colname) {
var isFound = false;
var rows = grid.jqGrid('getRowData');
for (var i = 0; i < rows.length; i++) {
var row = rows[i];
if (value == row.ezyid && value != '') { isFound = true };
}
if(isFound){
return [false, "This Ezy ID is in use, please enter another or press Cancel."];
} else {
return [true, ""];
}
}
我不太理想的尝试使用从afterShowForm:
添加模式表单选项的选项访问的自定义函数(如果必须以这种方式完成,在编辑中将类似使用):
addSettings = {
recreateForm: true,
jqModal: false,
reloadAfterSubmit: false,
closeOnEscape: true,
closeAfterAdd: true,
afterShowForm: function ($form) {
var form = $form.parent()[0];
$("#ezyid", form).blur(function () { //or focusout() if better
var resp = chkDuplicateEzyids($(this).val(), 'Ezy ID');
if (!resp[0]) {
$("#FormError", form).show();
$(".ui-state-error", form).html(resp[1]);
}
});
$("#lui_" + grid[0].id).hide();
},
onclickSubmit: onclickSubmitLocal
},
总而言之,我想使用 focusout(或模糊)来立即测试文本字段值,而不是必须输入表单的所有其他值才能到达提交按钮,然后才发现该值已在使用中。这似乎是一种常见的做法,但在这种情况下我无法弄清楚。许多TIA。
(一些代码片段经批准重用,感谢stackoverflow用户@Oleg)