Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kendo UI: Force update of ViewModel on KeyPress in TextBox

I have a textbox field that has its value property bound to a property in my ViewModel.

The problem is that the ViewModel is by default updated on the "changed" event of the textbox (when the textbox loses its focus).

I want the ViewModel to be updated when the keypress event is executed.

I don't want to force the "changed" event in every keypress, as there is some logic in that event handler and it doesn't have to be executed for every keystroke.

Is there a way to tell Kendo to update the ViewModel without triggering the "changed" event?

I know I can just manually modify the ViewModel, but I wanted something simpler and automated.

Thanks for your answers,

  • Will
like image 729
willvv Avatar asked Jul 09 '14 16:07

willvv


1 Answers

Use the data-value-update attribute. Using the "keypress" event does not update the last character to the bound model, so use the "keyup" event instead.

<input id="name" type="text" 
    data-bind="value: name" data-value-update="keyup">

I initially tested using "keypress", but entering text "abcd" results in "abc" in the ViewModel.

like image 200
cheino Avatar answered Sep 28 '22 09:09

cheino