jqgrid editoptions custom_func与required = false [英] jqgrid editoptions custom_func with required=false
问题描述
当我设置editrules custom_func且required = false时,custom_func仅在用户输入值时有效.我的意思是,如果用户将输入留空,则jqgrid将跳过custom_func. 就我而言,我想验证字段值是否为空,具体取决于同一行中的其他用户值.因此,我无法在colmodel中设置required = false,因为我需要在提交后对其进行验证.
When I set editrules custom_func and required=false, the custom_func only works if the user enter a value. I mean, if the user leaves the input empty, the custom_func is skipped by jqgrid. In my case, I want to validate if a field value may be empty or not, depending on other user values from the same row. So I can't set required=false in the colmodel, since I need to validate it after submit.
这是一个伪custom_func,请不要关注其内容:
This is a pseudo-custom_func, don't pay attention on its content:
colmodel: [
{name:'xxx', editrules: {
required:false,
custom:true,
custom_func: function(value) {
if(othercolumn=='blah' && value=='' ) {
//this is error
} else {
//this is correct
}
}
}}
]
我正在使用jqGrid 4.6.0(我仍在单独的分支中测试免费的4.13.6)
I am using jqGrid 4.6.0 (I am still testing free 4.13.6 in separate branch)
推荐答案
首先,我认为您发布了错误的代码属性.我猜您在editrules
内而不是editoptions
内使用了required
,custom
和custom_func
(请参见
First of all I think that you posted wrong properties of your code. I guess that you use specify required
, custom
and custom_func
inside of editrules
and not inside of editoptions
(see the documentation).
第二,您应该始终包括有关您使用(可以使用)的jqGrid版本以及有关jqGrid分支的信息( Guriddo jqGrid JS 或版本< = 4.7中的旧jqGrid).不同版本和不同jqGrid分支的可能性不同.
Seconds you should always include the information about the version of jqGrid, which you use (can use), and about the fork of jqGrid (free jqGrid, commercial Guriddo jqGrid JS or an old jqGrid in version <=4.7). The possibilities of different versions and different fork of jqGrid are different.
要解决您的问题,您应该不要在列中指定 required
属性或使用required: undefiled
.仅在使用required: false
,则不会在空值上调用custom_func
.其他任何值,如required
属性的true
和false
,将允许您进行自定义验证.
To solve your problem you should don't specify required
property in the column or to use required: undefiled
. Only in case of explicit usage of required: true
the validation will be stopped by empty value. If you specify explicitly required: false
, then custom_func
will be not called on empty value. Any other values as true
and false
of required
property will allow you to make custom validation.
您遇到的下一个问题是要求访问另一列的值以进行自定义验证.它应该是单独问题的一部分.了解您使用的jqGrid的分支,jqGrid的版本和编辑模式(内联编辑,表单编辑或单元格编辑)非常重要.
The next problem, which you have is the requirement to access to the value of another column for custom validation. It should be a part of separate question. It's important to know the fork of jqGrid, which you use, the version of jqGrid and the editing mode (inline editing, form editing or cell editing).
这篇关于jqgrid editoptions custom_func与required = false的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!