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

Suppress 'change' event within 'select' event?

3 Answers 1897 Views
AutoComplete
This is a migrated thread and some comments may be shown as answers.
Ed
Top achievements
Rank 1
Ed asked on 30 Jul 2014, 12:21 AM
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

3 Answers, 1 is accepted

Sort by
0
Accepted
Georgi Krustev
Telerik team
answered on 30 Jul 2014, 11:46 AM
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!
 
0
Rubens
Top achievements
Rank 2
answered on 13 Oct 2016, 04:55 PM

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?

0
Georgi Krustev
Telerik team
answered on 14 Oct 2016, 11:08 AM
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.
 
Tags
AutoComplete
Asked by
Ed
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Rubens
Top achievements
Rank 2
Share this question
or