This is a migrated thread and some comments may be shown as answers.

Change event not fired when setting value from code

4 Answers 1395 Views
NumericTextBox
This is a migrated thread and some comments may be shown as answers.
László
Top achievements
Rank 1
László asked on 20 Nov 2013, 11:43 AM
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?

4 Answers, 1 is accepted

Sort by
0
Accepted
Georgi Krustev
Telerik team
answered on 20 Nov 2013, 01:40 PM
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!
0
Bilal
Top achievements
Rank 2
answered on 01 Apr 2015, 06:08 AM
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
0
László
Top achievements
Rank 1
answered on 01 Apr 2015, 06:40 AM
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


0
Bilal
Top achievements
Rank 2
answered on 01 Apr 2015, 09:30 AM
Thanks László a lot :)
Tags
NumericTextBox
Asked by
László
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Bilal
Top achievements
Rank 2
László
Top achievements
Rank 1
Share this question
or