【发布时间】:2010-01-05 09:11:09
【问题描述】:
我目前正在使用 ci 框架开发 jqgrid。只是想问一下jqgrid中的验证。我已经看到在 jqgrid 中可以像这样验证列:editrules: {required:true}} 等等......
这是我的问题,我想知道如果客户输入他/她想要的用户名但它已经存在,是否有可能。这可能使用 jqgrid 验证吗?
谢谢 -院长
【问题讨论】:
我目前正在使用 ci 框架开发 jqgrid。只是想问一下jqgrid中的验证。我已经看到在 jqgrid 中可以像这样验证列:editrules: {required:true}} 等等......
这是我的问题,我想知道如果客户输入他/她想要的用户名但它已经存在,是否有可能。这可能使用 jqgrid 验证吗?
谢谢 -院长
【问题讨论】:
您可以使用custom edit rule 来完成此操作
这是文档中的示例
function mypricecheckforvalue(value, colname) {
if (value < 0 || value >20)
return [false,"Please enter value between 0 and 20"];
else
return [true,""];
}
jQuery("#grid_id").jqGrid({
...
colModel: [
...
{name:'price', ..., editrules:{custom:true, custom_func:mypricecheckforvalue....}, editable:true },
...
]
...
});
【讨论】:
这是我想出的解决方案
{name:'actualNo',index:'actualNo',editable:true, edittype:"text", width:150,editoptions:{
size: 15, maxlengh: 10,
dataInit: function(element) {
$(element).keyup(function(){
var val1 = element.value;
var num = new Number(val1);
if(isNaN(num))
{alert("Please enter a valid number");}
})
}
}},
【讨论】: