Highlight error cell or enter when validation fails in jqgrid

I am using jqgrid inline editing with grid validation using editing rules. I want to add a class to highlight errors (for example: ui-state-error) for input that fails during validation. I can set the class to highlight the error using this

jQuery ('#' + grid_id) .jqGrid ('setCell', row_id, errfields [a], '', 'ui-state-error', {color: 'blue'}); I>

But it does not work in jqgrid when the inline validation fails. How to highlight the backlight that caused the error caused by the cell / input.

+3
source share
2 answers

The demo shows how to solve the problem:

enter image description here

"", "" "" :

editrules:{required:true,number:true}

, "ui-state-error". jQuery UI CSS. , .

() $.jgrid.checkValues $.jgrid.hideModal. :

var grid = $("#list");
grid.jqGrid({
    // define all jqGrid options
});

var originalCheckValues = $.jgrid.checkValues,
    originalHideModal = $.jgrid.hideModal,
    iColWithError = 0;
$.jgrid.checkValues = function(val, valref,g, customobject, nam) {
    var tr,td,
        ret = originalCheckValues.call(this,val, valref,g, customobject, nam);
    if (!ret[0]) {
        tr = g.rows.namedItem(editingRowId);
        if (tr) {
            $(tr).children('td').children('input.editable[type="text"]').removeClass("ui-state-error");
            iColWithError = valref; // save to set later the focus
            //error_td_input_selector = 'tr#'+editingRowId+' > td:nth-child('+(valref+1)+') > input.editable[type="text"]:first';
            td = tr.cells[valref];
            if (td) {
                $(td).find('input.editable[type="text"]').addClass("ui-state-error");
            }
        }
    }
    return ret;
};
$.jgrid.hideModal = function (selector,o) {
    var input, oldOnClose, td,
        tr = grid[0].rows.namedItem(editingRowId);
    if (tr) {
        td = tr.cells[iColWithError];
        if (td) {
            input = $(td).children('input.editable[type="text"]:first');
            if (input.length > 0) {
                oldOnClose = o.onClose;
                o.onClose = function(s) {
                    if ($.isFunction(oldOnClose)) {
                        oldOnClose.call(s);
                    }
                    setTimeout(function(){
                        input.focus();
                    },100);
                };
            }
        }
    }
    originalHideModal.call(this,selector,o);
};
+5

jqgrid jquery, , . rowId_columnName , (, ..), . $('#1_name') 1, jquery , . $('#1_name').rules('add', {required:true}), , , $('#1_name').valid(), , . jqgrid saveRow. , .

0

All Articles