Herb Caudill
Herb Caudill

Reputation: 49952

jQuery Validation plugin with JQGrid?

Has anyone successfully used the jQuery Validation plugin with JQGrid? I realize that JQGrid has its own validation scheme, but it's limited and a little clumsy; and I'd prefer to reuse the validation UI, language, and rules that I'm using with the rest of my forms.

Upvotes: 2

Views: 6104

Answers (1)

calca
calca

Reputation: 61

Edit inline and Validations is possibile with this steps.

Write your function to highlight and unhilight your input box:

GridErrorHighlight = function(el, er, ev) {
    $(el)
        .addClass('ui-state-error')
    .parent()
        .addClass('ui-state-error');
}

GridErrorUnHighlight = function(el, er, ev) {
    $(el)
        .removeClass('ui-state-error')
    .parent()
       .removeClass('ui-state-error');
}

Extend jqgrid:

; (function($) {
    $.jgrid.extend({
        onErrorHighlight: GridErrorHighlight,
        onUnHighlight: GridErrorUnHighlight,
    });
})(jQuery);

Now is easy for jQuery validation plugin use your custom functions. Is only necessary to create this options and initialize validation plugin:

var table = $('#tableid').jqGrid({});

var validateOpt = {
        meta: "validate",
        highlight: table.onErrorHighlight,
        unhighlight: table.onUnHighlight
    };

$(document).ready(function() {
    $('#formId').validate(val);
});

Now is easy to set validator for single input cell. We use jqGrid EditOptions into Model to add custom class for validation:

"editoptions":{"class":" {validate: { range:[0,1] } }"}

that's all!

Upvotes: 4

Related Questions