how can i validate in jqgrid

431 Views Asked by At

how to make my save button save only if it validates that a field is numeric if not, show message?

{ name: 'fechaHoraRegistro', index: 'fechaHoraRegistro', width: 90, editable: true, editoptions: {
            size: 15, maxlengh: 10,
                dataInit: function (es) {
                    $(es).datepicker({ dateFormat: 'dd-mm-yy' });                            
                },
            }
        },
        {
            name: 'horaRegistro', index: 'horaRegistro', width: 0, editable: true, hidden: false, edittype: 'text', editoptions: {
                size: 15, maxlengh: 10,
                dataInit: function (element) {
                    $(element).keyup(function () {
                        var val1 = element.value;
                        var num = new Number(val1);
                        if (isNaN(num))
                        { alert("Ingresar solo numeros"); }
                    })
                }
            }
        },
1

There are 1 best solutions below

0
Tony Tomov On BEST ANSWER

You can use the build in validation. For this purpose you will need to use editrules. More you can find here in Guriddo jqGrid documentation.

In you case it is simple:

{
    name: 'horaRegistro', index: 'horaRegistro', width: 0, editable: true, hidden: false, 
    edittype: 'text', 
    editoptions: {
        size: 15, 
        maxlengh: 10,
    },
    editrules : { 
       number : true
    }
},

You also can set min max and other limitations.