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

Capture the Clear Event

1 Answer 221 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Joel
Top achievements
Rank 2
Iron
Iron
Iron
Joel asked on 19 Jun 2020, 12:48 AM

I have this combobox.  As expected the select event fires when I select an item (plus the change event) but does not fire when I clear (X) the selection.  The change event fires when I clear but then I don't know how to evaluate that nothing is selected.  How do I evaluate if the selection was cleared?

In my script for the change event, I get the first alert.  But, then the "if (e.item)" always falls to the else logic.

@(Html.Kendo().ComboBox()
    .Name("isActiveFilter")
    .Filter(FilterType.Contains)
    .Placeholder("No filter...")
    .DataTextField("Name")
    .DataValueField("Value")
    .BindTo(Model.IsActiveOptions)
    .Suggest(true)
    .Events(e =>
    {
        e.Select("onActiveFilterSelected");
        e.Change("onActiveFilterChanged");
    })
    .HtmlAttributes(new { style = "width:100%;" }))

Here are my event handlers:

function onActiveFilterChanged(e) {
    alert("change");
    if (e.item) {
        var dataItem = this.dataItem(e.item.index());
        alert("event :: change (" + dataItem.Name + " : " + dataItem.Value + ")");
    } else {
        alert("event :: change");
    }
}
 
function onActiveFilterSelected(e) {
    alert("select");
    if (e.item) {
        var dataItem = this.dataItem(e.item.index());
        alert("event :: select (" + dataItem.Name + " : " + dataItem.Value + ")");
    } else {
        alert("event :: select");
    }
}

 

1 Answer, 1 is accepted

Sort by
0
Martin
Telerik team
answered on 23 Jun 2020, 09:18 PM

Hello Joel,

Thank you for the code snippets.

I tested the provided code. The reason why the if(e.item) part is never executed is because e.item is available only in the select event. In order to capture the moment when the selection is cleared, I would recommend using the value method to check if the value of the ComboBox is empty string or not.

Let me know if that works for you.

Regards,
Martin
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
Tags
ComboBox
Asked by
Joel
Top achievements
Rank 2
Iron
Iron
Iron
Answers by
Martin
Telerik team
Share this question
or