Autocomplete selected item

1 Answer 50 Views
AutoComplete
Wreeecks
Top achievements
Rank 2
Iron
Iron
Iron
Wreeecks asked on 12 Oct 2021, 07:00 AM

how do I get the selected item ID when clicking the suggested item? 

below is my data structure. how do i get the ID instead of label?

[ { id: 1, label: 'Label 1'}, { id: 2, label: 'Label 2'} { id: 3, label: 'Label 3} ]

 

This is my component.

<AutoComplete
            data={results}
            textField="label"
            onChange={onChange}
            onBlur={onClose}
            placeholder="Search "
            value={keyword}
        />



1 Answer, 1 is accepted

Sort by
2
Accepted
Stefan
Telerik team
answered on 12 Oct 2021, 09:12 AM

Hello, Wreeecks,

Currently, we only return the value as the component focuses on the text and it allows free text. This means that in some cases there is not an actual item that has this value which means that there is no ID that is attached to that value as well. For example, the user can type 'test', and even if there is no object with a value test it will still be a valid value for the component.

If the ID is needed, it can be found from the text value during the onChange event. I made an example showcasing this:

https://stackblitz.com/edit/react-ckfm3j?file=app/main.tsx

Regards,
Stefan
Progress Telerik

Remote troubleshooting is now easier with Telerik Fiddler Jam. Get the full context to end-users' issues in just three steps! Start your trial here - https://www.telerik.com/fiddler-jam.
Wreeecks
Top achievements
Rank 2
Iron
Iron
Iron
commented on 12 Oct 2021, 09:37 PM

Thanks, Stefan! I was looking for something like the Grid onRowClick wherein you have access to the row data.

Anyway, this is will do the trick! thanks again!


Tags
AutoComplete
Asked by
Wreeecks
Top achievements
Rank 2
Iron
Iron
Iron
Answers by
Stefan
Telerik team
Share this question
or