Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Update Kendo NumericTextBox with MVVM on spin

Take a look at the MVVM example here:

How can I get the MVVM value to update on the spin event (clicking the up or down arrows)

Here is what I tried:

In the spin event, I tried to do

$("#ntb").getKendoNumericTextBox().trigger("change");

That worked but had weird side effects.

If there are enough elements on the DOM, the spin event will keep firing.

Another way to reproduce this is to take the code from here (jsbin)

Insert it in a HTML file, load it in Chrome or FF and then insert a break point at this line:

$("#ntb").getKendoNumericTextBox().trigger("change");

Keep hitting continue and you will see the breakpoint get hit time after time.

In firefox, if my DOM is large enough, I get a repro without a breakpoint.

like image 699
Matt Avatar asked Sep 30 '22 17:09

Matt


2 Answers

I checked your jsbin and I saw some errors in html and javascript. I think while you were testing different codes you forgot to correct it. Anyway I clean up and correct your codes and put them to this jsfiddle.

After putting breakpoint (debugger;) I saw you are right onSpin event triggers infinitely but this odd act happens if you put a breakpoint in the event. If you remove breakpoint and put a console.log("onSpinevent triggered."); you see everything is okay and the event just triggered just once.

I faced before with such issues in different scenarios for example using alert() instead of console.log() for debugging purpose.


Codes:

var viewModel = kendo.observable({
    selectedNumber: 0,
    isEnabled: true,
    isVisible: true,
    onSpin: function () {
        //debugger;
        console.log("`onSpin` event triggered.");
        $("#ntb").getKendoNumericTextBox().trigger("change");
    },
    onChange: function () {}
});
kendo.bind($("#example"), viewModel);
like image 93
Iman Mahmoudinasab Avatar answered Oct 04 '22 21:10

Iman Mahmoudinasab


Kendo support says to run this in the spin event:

this.set('selectedNumber', e.sender.element.val());

And that makes the problem go away.

like image 27
Matt Avatar answered Oct 04 '22 19:10

Matt