Hi everyone,
I am using the SyncFusion Autocomplete control, and I am generally quite happy with it. But I've noticed that it's rather agressive in selecting an item from the collection based on the input from the user, meaning that it seems to autofill the textfield with the item text.
This behaviour can make it hard for my users to actually pick the correct item since it "overrules" a lot. So if the user starts to delete the entered text, it seems the autofill-behavior auto-selects anything that matches, and sometimes even if it's not from the start of the entered word.
E.g: A user starts typing "Rock" and the autofill auto-selects "Rockstar", but the user wants to start over and needs to delete the input, so upon deletion the input now says "Roc", and the autofill selects any new item that could match, so now adding "Rocky Mountains" to the input field, making the user having to delete even more, and ending up in a sort of mismatch loop. Even while trying to delete the newly added text it could autofill to "Octagon" because "oc" was in the entered text.
The scenarios above is when using "StartsWith". When using "Contain" it seems to work a lot better in terms of letting the user actually type in the word for the thing they are looking for, because it's not autofilling the textfield. But this also takes a lot longer for the user to use based on the input.
So, I need to know if there's a way to disable the autofill when using "StartsWith", or if this is possible to change with any property, event or override?
Actually after a little bit of messing around, I can make the more "agressive" part go away. The autofill is still there but when entering or deleting the text input it no longer replaces or overrules the entered text.
What I did was adding a FilterBehavior that simply used the LINQ StartsWith function to kinda "override" the original StartsWith, although not altering the autofill, since it's not really a visible option.
Hi Christian,
We have reviewed your query, and currently, we do not have support for disabling autofill when using StartsWith in SfAutoComplete. Instead, we have utilized the CustomFilteringBehavior in SfAutoComplete. Based on your requirements, we have prepared a sample that includes SfAutoComplete with TextSearchMode set to Contains. Additionally, we have integrated the CustomFilteringBehavior, which functions similarly to StartsWith mode without autofill. We have attached the sample for your reference. Please review it and let us know the details.
Regards,
Ahamed Ali Nishad.
This was my solution. Using the Contain to "disable" the autofill, and then the StartsWith for proper sorting:
public async Task<object> GetMatchingItemsAsync(SfAutocomplete source, AutocompleteFilterInfo filterInfo)
{
IEnumerable itemssource = source.ItemsSource as IEnumerable;
var filteredItems = (from MyObject item in itemssource
where item.Property.Contains(filterInfo.Text, StringComparison.CurrentCultureIgnoreCase)
select item);
// Sort filtered items by "StartsWith" logic
var sortedItems = filteredItems.OrderBy(item =>
{
return item.Property.StartsWith(filterInfo.Text, StringComparison.OrdinalIgnoreCase) ? 0 : 1;
});
return await Task.FromResult(sortedItems);
}
Hi Christian,
We are happy to hear that you have found a solution on your end. We will mark this thread as solved. Please let us know if you need further assistance. As always, we are happy to help you out.
Regards,
Preethi R