Autocomplete - Get Object in Data List

Just like the autocomplete demo, I have an autocomplete with data comprised of a set of objects. However, unlike the demo, where just the string typed into the autocomplete is returned upon selection, I need to get the whole object. (Using the demo as an example, I would like to get the whole Customer object and not just the company name.) If I were using a dropdown or one of the other controls, I would just set the value property or bind the value to a selected object, but neither of these seem to work with the autocomplete component (no value property and get casting errors when I bind-value/bind-SelectedItem to an object).

Is there a way to get the whole object while using autocomplete, or is doing so beyond the scope of the component?

Thanks in advance for any assistance you can provide me on this issue.

2 Likes

Indeed the Autocomplete provides only the value of the property specified via TextProperty. It does not currently provide the "whole" object. You can use the DropDown instead with filtering enabled.

I don't understand why you don't add a SelectedItem property (and maybe an IdProperty) to make the control a lot more usable. There are code systems where the displayed values are similar but the associated identifiers are not, so having only the selected displayed text is useless.

It is a very simple cange, create a property of type object called SelectedItem, and in System.Threading.Tasks.Task SelectItem(object item), add this as the first line:

SelectedItem = item;

If you want I can submit a pull request.

2 Likes

@manu did you submit a pull request? i would like to add this functionality.

1 Like

I would like to +1 this. A string is pretty worthless when using a component like this. Even If I'm navigating to a detail page, I'll need a unique ID of sorts, not the readable string value.

Except I don't want to display all the data when the user clicks the dropdown. I only want to display possible selections when the user begins to type. Is there a way to not show the "list" in a dropdown list until the user begins to type? The dropdown control is not the proper control for this.

I`m at the same point. Implementing the Autocomplete and I canΒ΄t use it, because I need to get back the object or the unique ID which ist different to the TextProperty in which I search.

Example:
Searching in customer.Name but returning to the bind-value customer.ID

Like this is quite useless because two customers can have the same name.

@fabius916 use the DropDown component

Hi team, @korchev @enchev ,
Guys, I'm just starting with Radzen and love it!
I got a few bumps, but those were easy to fix. Now, I'm facing one that takes too much time, hence, I'm seeking for your advice, please.

My Autocomplete shows the object name, instead of its string property :slight_smile:


I'm passing a simple struct with 2 public properties: Code and Name (this one is a combination of Code + Some additional info)

Interestingly, that it's filtering by the value provided in the input, and the Change handler receives the struct with the right values

What am I doing wrong?

Make sure you have Name property on your objects.

Hi @enchev for your prompt response. Yes, it's there:
image

This is field, not property.

1 Like

@enchev Legend !!! Really appreciate it!
Thank you! That must be fatigue, should take a break :slight_smile:

image