AutoComplete control

The AutoComplete control allows searching and selecting a value from a data source. The selected value must be present in the data source. This is useful when the data source contains many elements that would make the form too long or slow if displayed all at once.
 
Customization
We can set a custom data source by specifying the value ControlClass for DataSourceMode and entering the namespace and class name in the CustomControlClass control property.
 
In the GetListValuesAsync method, we need to handle both the suggestion retrieval phase (parameter Title) and the retrieval, validation, and saving of the corresponding value (parameter Text).
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using DataWeb.Data;
using DataWeb.Data.Controls;
using DataWeb.Identity;
using DataWeb.Structure;
using MyApp.Infrastructure;
using MyApp.Structure;

namespace MyApp.DataWeb.Data.Controls
{
    public class Project_CompanyIdMaster : AutoComplete
    {
        private readonly CompanyStore companyStore;

        public Project_CompanyIdMaster(Form form, IServiceProvider serviceProvider) : base(form, serviceProvider)
        {
            companyStore = serviceProvider.GetService<CompanyStore>();
        }

        public override async Task<IEnumerable<List.ListItem>> GetListValuesAsync(Dictionary<string, object> parameters, IUser user, string itemId = null, NavigationContext navigationContext = null)
        {
            var companies = Enumerable.Empty<Company>();

            if (parameters.ContainsKey("Value"))
            {
                // Get selected items
                companies = await companyStore.GetCompaniesAsync(new CompanyStore.Filter { IdMaster = Convert.ToString(parameters["Value"]) });
            }

            if (parameters.ContainsKey("Title"))
            {
                // Get suggested items
                companies = await companyStore.GetCompaniesAsync(new CompanyStore.Filter { SearchText = Convert.ToString(parameters["Title"]) });
            }

            return companies.Select(x => new List.ListItem { Title = x.Name, Value = x.IdMaster, AdditionalValues = new List<List.ListItem.AdditionalValue>() });
        }
    }
}