KeyPress on input not worked

2019-07-29 22:11发布

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条回答
放我归山
2楼-- · 2019-07-29 22:32

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.

查看更多
登录 后发表回答