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
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
Thanks, it works fine
actually I used it for DataFormComboBoxItem with IsEditable=True
regards, alon
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
- 3 Replies
- 2 Participants
-
AL alon
- Sep 1, 2023 06:08 PM UTC
- Sep 5, 2023 11:36 AM UTC