简体   繁体   English

Kendo网格验证不适用于自定义网格行为

[英]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). 在两个单元格都具有新值之后,将单元格焦点设置到下一个单元格(如果按下Enter / Tab键,或者在下一个鼠标单击的单元格中都位于右侧单元格)。 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. 为了使所有这些正常工作,我必须编写自定义的refresh()current()函数,并在网格中使用自定义的edit()save()事件。 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. 在示例中,您可以在第一行中编辑单元格,然后按Enter或Tab键,下面的单元格将获得与编辑后的单元格相同的值。 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. 如果删除单元格的值,然后按Enter键,则不会显示验证错误。 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: Telerik的家伙为我提供了解决方案:

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);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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