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

Change event doesn't fire after clearing the value and selecting the same one

4 Answers 1915 Views
AutoComplete
This is a migrated thread and some comments may be shown as answers.
Chris
Top achievements
Rank 1
Chris asked on 14 Sep 2012, 12:02 PM
I know this may seem minor, but it's an issue I'm trying to fix.  If you have an autocomplete and select a value, then clear it with .val(''), then select the same value, the change event doesn't fire.  This is a problem because I'm using the autocomplete with knockout and the observable doesn't get updated.  See this fiddle: http://jsfiddle.net/rniemeyer/Z8yL8/ 

Select red, click Reset, select red again and you'll see that it doesn't log the change to the console.

Aside from the fact that I'm using knockout, the change event should fire if you select something, then clear the value, then select a value.  It only does that when the second value is different from the first, even though the value was empty between them.

Is there any workaround for this issue without waiting for a release?

Regards,
Chris Rock

4 Answers, 1 is accepted

Sort by
0
Alexander Valchev
Telerik team
answered on 19 Sep 2012, 07:14 AM
Hi Chris,

The reason for this behaviour is the fact that changing the value via JavaScript code does not trigger the change event of the widget (the same applies for elements bound to Kendo MVVM values). This is expected, as a workaround you can manually trigger the change of the AutoComplete.
$("#reset").click(function() {
   $("#test").data("kendoAutoComplete").value("");
   $("#test").data("kendoAutoComplete").trigger("change"); //trigger change
   $("#value").text("");
});

For convenience I updated your fiddle: http://jsfiddle.net/valchev/Z8yL8/3/ 

Regards,
Alexander Valchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Chris
Top achievements
Rank 1
answered on 19 Sep 2012, 02:25 PM
Thanks for the reply, but actually that still doesn't work.  Open the fiddle you posted and do this:
Type re and select red, the change event is fired.
Click Reset, the change event is fired.
Type re and select red, the change event is _not_ fired.  It should be,

0
Alexander Valchev
Telerik team
answered on 24 Sep 2012, 08:59 AM
Hello Chris,

Thank you for the feedback.
The problem comes from the fact that _old property of the widget is not cleared. I am glad to inform you that this issue has been addressed and is fixed in the latest build. As a temporary workaround I suggest resetting the value manually:
$("#test").data("kendoAutoComplete")._old = "";

To demonstrate the approach I updated the jsFiddle page: http://jsfiddle.net/valchev/Z8yL8/8/ 

Regards,
Alexander Valchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Chris
Top achievements
Rank 1
answered on 28 Sep 2012, 08:01 PM
I can confirm this worked for me, thanks.  

I tried to edit my 2012 Q2 source to put the fix in there, but that didn't work out too well.  I'll wait for the next release.

Chris
Tags
AutoComplete
Asked by
Chris
Top achievements
Rank 1
Answers by
Alexander Valchev
Telerik team
Chris
Top achievements
Rank 1
Share this question
or