jQuery UI Widgets Forums Grid shared validation function

This topic contains 1 reply, has 2 voices, and was last updated by  Hristo 7 years, 1 month ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
  • shared validation function #92991

    thanosk
    Participant

    Hello everyone,
    is it possible to validate a column using a function? Suppose that I have a grid with 10 columns, 5 out of them have to follow a common validation rule (length as an example), do I have to repeat the “validation : function (…” part in every columns’ declaration? I see that the function, if available should return a result and a message so,

    validation: function (cell, value) { validateLength(value,5);}

    where

    function validateLength(value, myLength) {
                    if (value.length > myLength) {
                        return { result: false, message: "Field must be up to " + myLength + " chars" };
                    }
                    return true;
                };

    but I am missing something.

    shared validation function #93023

    Hristo
    Participant

    Hello thanosk,

    You could use one same validation function for all columns, but you need to refer to that function.
    You should set validation for each one column that you desire to be validated.
    Note: You need to use same arguments as in the validation callback

    
    function validateLength(cell, value) { //Do validation };
    ...
    {
    	text: 'Quantity', datafield: 'quantity', width: 70, align: 'right', cellsalign: 'right', columntype: 'numberinput',
    	validation: validateLength
    }, {
    	text: 'Price', datafield: 'price',
    	validation: validateLength
    }

    Best Regards,
    Hristo Hristov

    jQWidgets team
    http://www.jqwidgets.com

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.