Dynamically change helperText/placeholder for SfTextInputLayout in dataForm

Hello there,

I'm stuck for a few days and cannot make this behavior working.
I tried it with autogenerated items and also without it, but no progress was made.

What I'm trying to do in my dataForm, is to dynamically change placeholder text under SfTextInputLayout combobox  when user select one item from selection, placeholder text under the combobox would change based on that selection.

Could you please navigate me, how could I make this working?

Thank you.


5 Replies 1 reply marked as answer

VM Vidyalakshmi Mani Syncfusion Team September 5, 2024 02:21 PM UTC

Hi Maros,


Thank you for reaching out to us. To dynamically update the `PlaceholderText` of a `ComboBox`, you can handle its `SelectionChanged` event. This can be achieved by using the `DataFormItemManager` class and overriding the `InitializeDataEditor` method. This method is called when initializing the data editor for a form item, allowing you to work directly with the `ComboBox` (`SfComboBox`) properties and events.


In the `SelectionChanged` event, you can retrieve the selected item from the `AddedItems` property and set this value as the helper text, as shown in the code example below:


MainPage.xaml.cs:

 public partial class MainPage : ContentPage

    {

        public MainPage()

        {

            InitializeComponent();

            this.dataForm.RegisterEditor("Category", DataFormEditorType.ComboBox);           

            this.dataForm.ItemManager = new DataFormItemManagerEditorExt();           

        }

    }

 

    public class DataFormItemManagerEditorExt : DataFormItemManager

    {

  

        public override void InitializeDataEditor(DataFormItem dataFormItem, View editor)

        {

           

            if (editor is SfComboBox comboBox)

            {

                comboBox.SelectionChanged += ComboBox_SelectionChanged;

            }

        }

 

        private void ComboBox_SelectionChanged(object? sender, Syncfusion.Maui.Inputs.SelectionChangedEventArgs e)

        {

            if (e.AddedItems != null && e.AddedItems.Count > 0)

            {

               ((sender as SfComboBox).Parent as SfTextInputLayout).HelperText = e.AddedItems[0].ToString();

 

            }

           

        }

    }

 


We’ve also prepared a sample to illustrate this implementation. Please check the attached sample for further reference.


If you need more help or have additional questions, feel free to get in touch!


Regards,

Vidyalakshmi M.



Attachment: MAUIDataForm_63b5540f.zip


MG Maroš Gorný September 9, 2024 07:55 PM UTC

Hmmm, thank you so much, it's working as expected.
But in my I'm using AutoGenerateItems="True".

Is it possible to make it functional also with this property turned on?



Regards,
Maros



VO Vishal Omprasad Syncfusion Team September 10, 2024 01:50 PM UTC

Hi Maros,

Your requirement to set the ItemsSource for combo box editor when AutoGenerateItems is true, can be achieved by using the GenerateDataFormItem event.

We have modified our previously shared sample and have attached it below for your reference. Please check the attached sample and let us know whether your requirement is achieved.

Please refer to the following UG link on how to set the ItemsSource for combo box editor when AutoGenerateItems is true: Combo Box editor.

We hope that this helps you. Please let us know if you need further assistance.

Regards,
Vishal O.


Attachment: MAUIDataForm_d6191c4.zip

Marked as answer

MG Maroš Gorný replied to Vishal Omprasad September 10, 2024 07:11 PM UTC

Thank you Vishal.
That's what I needed. 

I appreciate your help with added attachments.

Regards,
Maros



VO Vishal Omprasad Syncfusion Team September 11, 2024 10:07 AM UTC

Hi Maroš,

We are glad that our suggested solution meets your requirement. Please let us know if you need any further update. As always, we are happy to help you out.

Regards,
Vishal O.


Loader.
Up arrow icon