amit_g
amit_g

Reputation: 31250

Kendo UI Auto Complete when user does not select an option from the suggestions

When using Kendo UI Autocomplete with filter: 'contains' and suggest: true if the user types-in a value that causes a match in the middle (say kingdom in the demo) and tabs out, the value becomes kingdom and not United Kingdom as one would expect. This causes data entry errors. Anyway to enforce the desired behavior? We want the users to be able to type-in anything if they could not find any option so mandating a selection isn't an option but we want the users to be able to pick a selection once they find it rather than current behavior where if the tab, they lose the found selection unless they select it manually... something like if they typed in the value that matches in the starting (e.g. united in the demo) and tabing out. The match using contains instead of startsWith is also desirable.

Upvotes: 1

Views: 2149

Answers (1)

topalkata
topalkata

Reputation: 2098

As the Kendo UI AutoComplete allows for custom values (a behavior that you are saying you want to keep), the widget does not have a built-in way to distinguish between a custom value, and a match that you want to select from the list (like in the example - when the user types "united" and presses TAB, he may simply want the widget to have value "united", and not necessarily "United Kingdom").

You can achieve the desired behavior by implementing some custom "blur" event handler, and setting the value of the AutoComplete to be the one from the list, if for example the length of the list is 1 when the user presses TAB, or otherwise blurs the widget's input, for example:

Modified example

Upvotes: 2

Related Questions