简体   繁体   中英

Kendo grid validation not working with custom grid behavior

I can not get validation to work in my custom grid. The grid is designed to change the value of cell below the edited cell. After both cells have new values, cell focus is set to the next cell (cell to the right if enter/tab is pressed, or whichever cell is mouse-clicked next). In order for all that to work, I had to write custom refresh() and current() functions and use custom edit() and save() events in the grid. I also use custom editor in cells, which removes the spinners and selects the cell's value.

I have made a simplified working example which shows that validation is not working. In the example you can edit a cell in the first row, and when you press enter or tab, cell below will get the same value as the edited cell. Custom functions and events are necessary in order for both mouse and keyboard focusing to work so I have to use them.

If you delete the cell's value, and press enter no validation error will be shown. I suppose this has something to do with all custom functions and events I use. Is there a way to make the validation work?

EXAMPLE

I got it to work, the problem was within the custom column editor function. Guys at Telerik provided me the solution:

The validation is not triggered due to the missing validation attributes. As you may know, when custom column editor is used, the developer is responsible for adding the appropriate validation attributes to the correct elements within this editor.

function editNumberWithoutSpinners(container, options) {

    // add name attribute to connect the validation placeholder with the validated element
    $('<input name="' + options.field + '" data-text-field="' + options.field + '" ' +
        'data-value-field="' + options.field + '" ' +
        'data-bind="value:' + options.field + '" ' +
        'data-format="' + options.format + '" required="required"/>') // add the validation attributes
        .appendTo(container)
        .kendoNumericTextBox({
            spinners: false,
            min: 0
        });

    // custom validation message placeholder is required due to the way NumericTextBox is rendered
    $('<span class="k-invalid-msg" data-for="' + options.field + '"></span>').appendTo(container);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM