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

5 posts, 0 answers
  1. Chris
    Chris avatar
    3 posts
    Member since:
    Sep 2012

    Posted 14 Sep 2012 Link to this post

    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

  2. Alexander Valchev
    Admin
    Alexander Valchev avatar
    2877 posts

    Posted 19 Sep 2012 Link to this post

    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!
  3. Kendo UI is VS 2017 Ready
  4. Chris
    Chris avatar
    3 posts
    Member since:
    Sep 2012

    Posted 19 Sep 2012 Link to this post

    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,

  5. Alexander Valchev
    Admin
    Alexander Valchev avatar
    2877 posts

    Posted 24 Sep 2012 Link to this post

    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!
  6. Chris
    Chris avatar
    3 posts
    Member since:
    Sep 2012

    Posted 28 Sep 2012 Link to this post

    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
Back to Top
Kendo UI is VS 2017 Ready