We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

itemData passed to change event contains incorrect row from dataSource

We have an autocomplete dropdown of zipcodes grouped by city names. There are some cases where 2 cities have the same zipcode:

When the user selects an entry like this, the data passed to the change event is wrong. Specifically, the "itemData" property of the argument contains always the first instance of the zipcode in the datasource, not the actually selected one, so the returned city name is wrong. The "item" property on the other hand contains the correct user selected row. Please see attached picture of firefox console log:

4 Replies

NP Narayanasamy Panneer Selvam Syncfusion Team September 3, 2019 11:14 AM UTC

Hi András, 
Greetings from Syncfusion support. 
We have validated your query. The reported issue is occurred because of you have mapped fields property to AutoComplete that contains duplicate items to the value property. In AutoComplete the items must be unique. For your requirement we suggest you use ComboBox, instead of using AutoComplete. In ComboBox, we have text and value property. Also, it has the filtering support which is similar to AutoComplete. In the below example we have mapped Id to value API and Zipcode to text API. 
Code example: 
<ejs-combobox id="city" placeholder="Select a Zipcode" popupHeight="200px" dataSource="@ViewBag.data" change="onChange"> 
<e-combobox-fields groupBy="Category" value="Id" text="Zipcode"></e-combobox-fields> 
public class City 
public int Zipcode { get; set; } 
public string Category { get; set; } 
public string Id { get; set; } 
public List<City> CityList() 
List<City> city = new List<City>(); 
city.Add(new City { Zipcode = 7300, Category = "Mecsekpoloske", Id = "item1" }); 
city.Add(new City { Zipcode = 7300, Category = "Komlo", Id = "item2" }); 
return city; 
Please find the screenshot for your reference, 
For your convenience we have prepared a sample. Please get it from the below link, 

Narayanasamy P. 

AN András September 3, 2019 11:19 AM UTC

Great, thank you very much for the clarification!

AN András September 3, 2019 03:21 PM UTC

Unfortunately after checking the solution in depth and trying to implement it in various ways I've found out that it requires us to post the zipcode as an Id number, instead of the plain zipcode string. Our application uses zipcodes in many places, and this solution needs a lot of work to be done, and needs database modification. Since we only need the City name to update another field's value from javascript, at this point I'm considering simply parsing the html node for the city name.

NP Narayanasamy Panneer Selvam Syncfusion Team September 5, 2019 03:51 AM UTC

Hi András,  
Thanks for the update. please let us know if you need any further assistance. 
Narayanasamy P. 

Live Chat Icon For mobile
Up arrow icon