0 Comments

To see the code in action, see this Plunker: http://plnkr.co/SpYSwv

 

The following HTML page shows a input box.

When the users start typing in the input box the SPAN element next to it will show the value just entered (onkeypress).

 

image

<!DOCTYPE html>
<html>
<head>
    <title>Kendo element binding research page.</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        body {
            padding: 20px;
        }
    </style>
    <link href="//cdn.kendostatic.com/2014.1.528/styles/kendo.common.min.css" rel="stylesheet" type="text/css" />
    <link href="//cdn.kendostatic.com/2014.1.528/styles/kendo.silver.min.css" rel="stylesheet" type="text/css" />
    <script src="//code.jquery.com/jquery-1.9.1.min.js"></script>
    <script src="//cdn.kendostatic.com/2014.1.528/js/kendo.all.min.js"></script>
</head>
<body>
    <div id="view">
        <input data-bind="value: inputValue, events: { keypress: showValueOnLabel }" />
        <span data-bind="text: label"></span>
    </div>
    <script>
        var viewModel = kendo.observable({
            inputValue: "Enter some text",
            label: "",
            showValueOnLabel: function (e) {
                var pressedKey = String.fromCharCode(e.charCode);
                var currentValue = e.currentTarget.value;
                this.set("label", currentValue + pressedKey);
            }
        });

        kendo.bind($("#view"), viewModel);
    </script>
</body>
</html>

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Related Posts