Kendo UI: Force ViewModel Update on KeyPress in TextBox

I have a textbox field that has a value property associated with a property in my ViewModel.

The problem is that the ViewModel is updated by default in the “changed” text field event (when the text field loses focus).

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

I don’t want to force a “changed” event to happen every time a key is pressed, since there is some logic in this event handler and it should not be executed for every key press.

Is there a way to tell Kendo to update the ViewModel without triggering a “modified” event?

I know that I can simply modify the ViewModel manually, but I needed something more simple and automatic.

Thank you for your responses,

  • Will it
+6
source share
3 answers

Use the attribute update-value-update. Using the keypress event does not update the last character of the anchored model, so use the keyup event instead.

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

At first I tested using "keypress", but entering the text "abcd" leads to "abc" in the ViewModel.

+10
source

You can add the data-value-update attribute to the element:

 <input data-bind="value: someValue" data-value-update="keypress" /> 

The documentation is here: Management when updating ViewModel

0
source
  <input type="text" data-value-update="keypress" data-bind="value: searchBySystemValue, events: { keypress: onkeypressEvent }"/> 

U can add function to events

0
source

Source: https://habr.com/ru/post/971984/


All Articles