jQuery UI Widgets Forums Grid Column Validation

This topic contains 4 replies, has 2 voices, and was last updated by  nishan 9 years, 7 months ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
  • Column Validation #59908

    nishan
    Participant

    Hi,

    In my project I need to restrict the user to enter only alphanumeric with underscore in one column of my grid. If they enter any other characters it should not appear in the cell. How can I attain this in jqwidgets grid?

    Column Validation #59953

    Dimitar
    Participant

    Hello nishan,

    You can bind to the editor’s keydown event in the column’s createeditor callback function. In the keydown event handler check if the entered character is valid and return false if not.

    Best Regards,
    Dimitar

    jQWidgets team
    http://www.jqwidgets.com/

    Column Validation #59991

    nishan
    Participant

    Hello Dimitar,

    Thank you for your timely response. Can you please provide the snippet of code for handling the keydown event in create editor or an example for the same?

    Regards,
    Nisha

    Column Validation #60018

    Dimitar
    Participant

    Hi Nisha,

    Here is an example column definition:

    columns: [
        { text: 'First Name', columntype: 'textbox', datafield: 'firstname', width: 120,
            createeditor: function (row, cellvalue, editor) {
                var regex = new RegExp(/\w/);
                editor.keydown(function (event) {
                    var char = event.char;
                    if (!regex.test(char)) {
                        event.preventDefault();
                    }
                });
            }
        },

    Best Regards,
    Dimitar

    jQWidgets team
    http://www.jqwidgets.com/

    Column Validation #61474

    nishan
    Participant

    Thank you Dimitar. It is working as expected.

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

You must be logged in to reply to this topic.