Kendo comboBox验证

时间:2018-05-25 12:48:19

标签: javascript jquery html kendo-ui kendo-grid

我的问题是每当我输入组合框中已经存在的文本项目时,我就会选择该组合框,组合框不会保存我的条目。它只剩下selectedIndex = 0.所以我的列表是{hi,hello,hey},我在组合框中输入hi,它应该保存我的文本,即使我没有从下拉列表中选择它。

Id: {
                            type: "number",
                            validation: {
                                idvalidation: function (input) {
                                    if (input.is("[name='Id']") && input.val() !== "") {
                                        input.attr("data-idvalidation-msg", "Please select a Code");
                                        return input.val() >= 0 && $("#Id").data("kendoComboBox").selectedIndex >= 0;
                                    }
                                    return true;
                                }
                            }
                        },
                        Code: { type: "string" },

1 个答案:

答案 0 :(得分:0)

这是Kendo Combobox的默认行为。如果要在选择选项卡后选择已过滤的项目(不单击列表中的选定项目),则必须添加一些JavaScript以捕获按键(ASCII代码9),如:

combobox.input.on("keydown", function(e) {
      var filter = combobox.dataSource.filter() || { filters: [] };

      if (e.keyCode === 9 && filter.filters[0]) { //TAB
        combobox.select(combobox.current().index());
      }
});

以上是代码Kendo's example的链接。

相关问题