Aberel
Aberel

Reputation: 162

jqgrid editoptions custom_func with 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.

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
         }
     }
  }}
]

EDIT: I am using jqGrid 4.6.0 (I am still testing free 4.13.6 in separate branch)

Upvotes: 0

Views: 1098

Answers (1)

Oleg
Oleg

Reputation: 221997

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).

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.

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.

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).

Upvotes: 2

Related Questions