Change event not fired when setting value from code

5 posts, 1 answers
  1. László
    László avatar
    12 posts
    Member since:
    Jul 2008

    Posted 20 Nov 2013 Link to this post

    Hi,

    I found a strange behaviour of the numerictextbox's change event. If I change the value of the widget from code it doesn't fire the change event:
    <body>
      <input id="numerictextbox" />
      <script>
      var textBox = $("#numerictextbox").kendoNumericTextBox({
        change: function() {
            var value = this.value();
            alert(value);
          }
      }).data("kendoNumericTextBox");
       
        textBox.value(12345); // this should fire change event.
      </script>
    </body>
     Is it by design behaviour, or is it a bug?
  2. Answer
    Georgi Krustev
    Admin
    Georgi Krustev avatar
    3707 posts

    Posted 20 Nov 2013 Link to this post

    Hello,

    This behavior is by design. Widget will raise change event only on user interaction. Find more information about this here.

    Regards,
    Georgi Krustev
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. Kendo UI is VS 2017 Ready
  4. Bilal
    Bilal avatar
    109 posts
    Member since:
    Oct 2014

    Posted 01 Apr 2015 in reply to Georgi Krustev Link to this post

    Hi,
    I was looking for the same problem online and passed by this post.

    The link for trigger method is broken on the page mentioned above.

    http://docs.telerik.com/kendo-ui/api/framework/widget#trigger

    How to trigger event on numerictextbox after setting its value by code?

    Thanks
  5. László
    László avatar
    12 posts
    Member since:
    Jul 2008

    Posted 01 Apr 2015 in reply to Bilal Link to this post

    Hello Bilal,

    Try this:

    <!DOCTYPE html>
    <html>
    <head>
      <meta charset="utf-8">
      <title>Untitled</title>
     
     
      <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
      </head>
    <body>
        <input id="numerictextbox" />
      <button onclick="changeValueFromCode()">Click to change value from code</button>
      <script>
     
      var textBox = $("#numerictextbox").kendoNumericTextBox({
        change: function() {
     
            var value = this.value();
            alert('value changed to: ' + value);
          }
      }).data("kendoNumericTextBox");
         
        function changeValueFromCode()
        
        textBox.value(12345);
        textBox.trigger('change');
        }
         
      </script>
    </body>
    </html>


    The documentation is here about trigger:

    http://docs.telerik.com/kendo-ui/api/javascript/ui/widget#methods-trigger


  6. Bilal
    Bilal avatar
    109 posts
    Member since:
    Oct 2014

    Posted 01 Apr 2015 in reply to László Link to this post

    Thanks László a lot :)
Back to Top
Kendo UI is VS 2017 Ready