AutoComplete editor

I am using DataFormAutoCompleteItem  as the editor of one of fields of the DataObject of the SfDataForm.

The appropriate DataObject filed is of type string.

When the user selects one of the items of ItemsSource of the editor the field value is updated properly.

But when the user type  a new value which is not at the ItemsSource of the editor, the field value is not updated.


Is this the right behavior?

I want to suggest the user a value, but also allow them to enter new value... 

With Regards, alon


3 Replies

SS SaiGanesh Sakthivel Syncfusion Team September 4, 2023 01:26 PM UTC

Hi Alon,


As per the implementation, the DataFormAutocomplete editor will update only the itemsource value in the editor value. We suggest you use the help of DataFormItemManagerExt Class to commit the entered text value to the editor value. Please refer to the following code snippet for your reference.


Code Snippet

public MainPage()

{

    InitializeComponent();

    dataForm.RegisterEditor("Country", DataFormEditorType.AutoComplete);

    this.dataForm.ItemManager = new DataFormItemManagerEditorExt(this.dataForm);

}

 

public class DataFormItemManagerEditorExt : DataFormItemManager

{

    SfDataForm dataform;

 

    public DataFormItemManagerEditorExt(SfDataForm dataForm)

    {

        this.dataform = dataForm;

    }

 

    public override void InitializeDataEditor(DataFormItem dataFormItem, View editor)

    {

        if (editor is SfAutocomplete autoComplete)

        {

            autoComplete.Unfocused += AutoComplete_Unfocused;

        }

    }

 

    private void AutoComplete_Unfocused(object sender, FocusEventArgs e)

    {

        var autocomplete = sender as SfAutocomplete;

        var text = autocomplete.Text;

        if (string.IsNullOrEmpty(text))

            return;

 

        var selectedItem = autocomplete.SelectedItem;

        if (selectedItem == null || selectedItem.ToString() != text)

        {

            (dataform.DataObject as ContactInfo).Country = text;

        }

    }

}


Please refer to the demo sample in the attachment. Please let us know if you have any concerns.


Regards,
SaiGanesh Sakthivel


Attachment: DataFormMAUI_fde1c571.zip


AL alon September 4, 2023 02:54 PM UTC

Thanks, it works fine

actually I used it for DataFormComboBoxItem  with IsEditable=True


regards, alon

 



SS SaiGanesh Sakthivel Syncfusion Team September 5, 2023 11:36 AM UTC

Alon,


We are glad to know that the provided solution is resolved the query. Please let us know if you need any further assistance on this. 


Regards, 

SaiGanesh Sakthivel


Loader.
Up arrow icon