KeyPress on input not worked

半腔热情 提交于 2019-12-14 03:58:25

问题


I need create keyPress (enter) binding for input.

<div id="body">
    <input type="text" data-value-update="keyup" data-bind="value: text, keyPress: onKeyPress"/>
    <div id="output"></div>
</div>

js:

kendo.data.binders.widget.keyPress = kendo.data.Binder.extend({
    init: function (element, bindings, options) {
        kendo.data.Binder.fn.init.call(this, element, bindings, options);
        var binding = this.bindings.keyPress;
        $(element.input).bind("keypress", function (e) {
            if (e.which == 13) {
                binding.get();
            }
        });
    },
    refresh: function () { }
});

var viewModel = kendo.observable({
    text: '',
    onKeyPress: function () {
        $("#output").append("<div>keyPress</div>");
    }
});

kendo.bind("#body", viewModel);

I had have error:

Error: The keyPress binding is not supported by the input element

Example in jsfiddle http://jsfiddle.net/dude_jsfiddle/byA75/


回答1:


The kendo.data.binders.widget namespace should be used when creating widget bindings. Widgets are created for elements that have their role data attribute set. You need kendo.data.binders only:

kendo.data.binders.keyPress = kendo.data.Binder.extend({
});

More info is available in the custom binding help topic.



来源:https://stackoverflow.com/questions/16709192/keypress-on-input-not-worked

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!