Suppress 'change' event within 'select' event?

4 posts, 1 answers
  1. Ed
    Ed avatar
    168 posts
    Member since:
    Sep 2013

    Posted 29 Jul 2014 Link to this post

    I am using my autoComplete as a filter.  I want to filter a dataSource using the 'eq' operator when the user selects an item in the autoComplete drop down.  I want to filter the dataSource using the 'contains' operator when the user presses the enter key when typing in the autoComplete text box.

    I am using both the 'change' and the 'select' events.
    From the docs:
    'change' - Fired when the value of the widget is changed by the user
    'select' - Fired when an item from the suggestion popup is selected by the user

    So...
    I'm using the 'change' event to filter when the user clicks enter (and therefore use 'contains' operator to filter the ds)
    I'm using the 'select' event to filter when the user clicks on a menu item (and therefore use 'eq' operator to filter the ds)

    It works well, except when the user selects an item in the drop down, the 'select' event gets fired and then the 'change' event gets fired immediately after.  How can I suppress the 'change' event whenever the 'select' event gets fired?

    Thanks,
    --Ed
  2. Answer
    Georgi Krustev
    Admin
    Georgi Krustev avatar
    3706 posts

    Posted 30 Jul 2014 Link to this post

    Hello Ed,

    In general, the select  event is preventable. This means that the selection will be prevented and change event will not be raised. This is the only way to prevent change event. To prevent it just call preventDefault:
    function select(e) {
      e. preventDefault();
    }
    Other option is to use a flag variable, which will notify you that select event is raised before change event and thus to perform different action.

    Regards,
    Georgi Krustev
    Telerik
     
    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. RMC
    RMC avatar
    3 posts
    Member since:
    Mar 2011

    Posted 13 Oct in reply to Georgi Krustev Link to this post

    Hi Georgi,

    Considering ComBox has now a shortcut to clean it up, how would we prevent this [X] click once it's not a select event?

  5. Georgi Krustev
    Admin
    Georgi Krustev avatar
    3706 posts

    Posted 14 Oct Link to this post

    Hi Rubens,

    I've answered to the support thread opened on the same subject. Let's continue our discussion in only one thread to avoid duplication.

    Here is a copy of the answer:

    The 'clear' button will directly change the value. That being said, only the 'change' event will be raised, as it is shown in our Events demo:

    http://demos.telerik.com/kendo-ui/combobox/events

    If the desire is to control the change conditionally, then I am afraid that you will need to do that in the changeevent handler.

    If you would like to disable that functionality, then you can use the clearButton configuration option.


    Regards,
    Georgi Krustev
    Telerik by Progress
     
    Get started with Kendo UI in days. Online training courses help you quickly implement components into your apps.
     
Back to Top
Kendo UI is VS 2017 Ready