Floting label floats even on dropdown with predefined value

Hi

I have the problem that a floating label for dropdown fields float when the form is opened even it is not possible to have an empty value. The layout type is: 

LayoutOptions = LayoutType.TextInputLayout

How can I remove the animation for floating labels on certain fields, e.g. dropdown?

Kind Regards,

Bruno


10 Replies

SS SaiGanesh Sakthivel Syncfusion Team February 22, 2022 11:10 AM UTC

Hi Burno, 
 
#Regarding Floting label floats even on dropdown with predefined value 
We could not to replicate the reported scenario from our side. We have prepared the sample as per the given information and checked the sample with android 9 (honor 9N device) API 28. We have attached the tested sample in the following link your reference. 
 
 
 
Please let us know if you have any concerns.

Regards,
SaiGanesh Sakthivel
 



ZI Zimmermann February 22, 2022 06:21 PM UTC

Hi 

Many thanks for the answer and example. I attached a short video to show the behaviour in the dataform with floating labels. The effect is visible on Android and iOS virtual as well as of physical devices like Samsung S10.


I hope it helps to better understand the problem.


Regards,

Bruno



Attachment: 22022022_140151_b6a1fa99.zip


SS SaiGanesh Sakthivel Syncfusion Team February 23, 2022 01:49 PM UTC

Hi Bruno, 
 
#Regarding Floting label floats even on dropdown with predefined value 
Currently, we are validating the reported scenario from our end. we will update you on the further details on February 25, 2022. We appreciate the patience until then. 
 
Regards,
SaiGanesh Sakthivel
 



SS SaiGanesh Sakthivel Syncfusion Team February 25, 2022 03:33 PM UTC

Hi Burno, 
  
#Regarding Floting label floats even on dropdown with predefined value 
Your requirement can be achieved with the help of CustomDropdownEditor class. We suggest you to set the IsHintAlwaysFloated property as true for the SfTextInputLayout inside the OnInitializeView override method. Please refer to the following code snippet for your reference. 
 
Code snippet 
dataForm.RegisterEditor("DropDown", new CustomDropDownEditor(dataForm)); 
dataForm.RegisterEditor("Country", "DropDown"); 
 
 

public
class CustomDropDownEditor : DataFormDropDownEditor 
    { 
        public CustomDropDownEditor(SfDataForm dataForm) : base(dataForm) 
        { 
        } 
        protected override void OnInitializeView(DataFormItem dataFormItem, SfComboBox view) 
        { 
            base.OnInitializeView(dataFormItem, view); 
            (view.Parent.Parent.Parent as SfTextInputLayout).IsHintAlwaysFloated = true; 
        } 
    } 
 
Please refer to the tested sample in the following locations. 
 
 
Please let us know if you have any concerns. 
 
Regards,
SaiGanesh Sakthivel
 



ZI Zimmermann February 28, 2022 08:26 PM UTC

Hi SaiGanesh

Many thanks for the help. I implemented the proposed solution and it works so far for all read only field in the dataform. Unfortunately, the other drop down filed has no floating label anymore (see attached print screen). I tried to define the custom editor for the one drop down only but I get a null pointer exception.


How can I archive having only one drop down without floating label?

Many thanks

Bruno


Attachment: dataform_28022022_161657_ddd08286.zip


SS SaiGanesh Sakthivel Syncfusion Team March 1, 2022 07:45 AM UTC

Hi Burno, 
 
#Regarding null pointer exception while using the Default layout 
Your requirement can be achieved with the help of CustomDropdownEditor class. We suggest you to check the type of the layout option inside the OnInitializeView override method. Please refer to the following code snippet for your reference. 
 
Code snippet 
public class CustomDropDownEditor : DataFormDropDownEditor 
{ 
    public CustomDropDownEditor(SfDataForm dataForm) : base(dataForm) 
    { 
    } 
    protected override void OnInitializeView(DataFormItem dataFormItem, SfComboBox view) 
    { 
        base.OnInitializeView(dataFormItem, view); 
        if (dataFormItem.LayoutOptions == LayoutType.TextInputLayout) 
        { 
            (view.Parent.Parent.Parent as SfTextInputLayout).IsHintAlwaysFloated = true; 
        } 
    } 
} 
 
Please refer to the tested sample in the following locations. 
 
Please let us know if you have any concerns.

Regards,
SaiGanesh Sakthivel
 



ZI Zimmermann March 8, 2022 03:37 PM UTC

Hi SaiGanesh

Many thanks for the replay. I have found a solution for the dropdown field which has always a value set.

            if
(dataFormItem.LayoutOptions == LayoutType.TextInputLayout &&
(dataFormItem.Name == "EventTypeCUID"))
            {
                (view.Parent.Parent.Parent as SfTextInputLayout).IsHintAlwaysFloated = true;
            }

Unfortunately, I'm not able to stop the floating label for a dropdown which has a value but is not mandatory (might be empty). I would like to have the floating label when no value is set and not a floating label like above when a value has been set. Do you have an idea how to archive this behaviour?

Many thanks,

Bruno 



SS SaiGanesh Sakthivel Syncfusion Team March 9, 2022 03:46 PM UTC

Hi Bruno,

#Regarding Disable Floating label when value is set in the field
 
Currently, we are checking the reported query from our end. We will update the further details on March 11, 2022. We appreciate the patience until then.  
  
Regards,  
SaiGanesh Sakthivel  



SS SaiGanesh Sakthivel Syncfusion Team March 11, 2022 02:53 PM UTC

Hi Bruno, 
 
#Regarding Disable Floating label when value is set in the field  
Currently, we are checking the reported query with SfTextInputLayout team. We will update the further details on March 15, 2022. We appreciate the patience until then.   
   
Regards,   
SaiGanesh Sakthivel   



SS SaiGanesh Sakthivel Syncfusion Team March 15, 2022 01:47 PM UTC

Hi Burno, 
 
#Regarding disable and enable the Floating label  
Your requirement can be achieved with the help of CustomDropdownEditor class and AutoGeneratingDataFormItem event. Inside the AutoGeneratingDataFormItem event, you can disable the hint label in the view. Please refer to the following code snippet for your reference. 
 
Code snippet 
private void DataForm_AutoGeneratingDataFormItem(object sender, AutoGeneratingDataFormItemEventArgs e) 
{ 
    if (e.DataFormItem != null) 
    { 
        if (e.DataFormItem.Name == "Country") 
        { 
            (e.DataFormItem as DataFormDropDownItem).DisplayMemberPath = "Name"; 
            (e.DataFormItem as DataFormDropDownItem).SelectedValuePath = "Name"; 
            if ((dataForm.DataObject as Address).Country == null) 
            { 
                (e.DataFormItem as DataFormDropDownItem).ShowLabel = true; 
            } 
            else 
            { 
                (e.DataFormItem as DataFormDropDownItem).ShowLabel = false; 
            } 
        } 
        if (e.DataFormItem.Name == "Country1") 
        { 
            (e.DataFormItem as DataFormDropDownItem).DisplayMemberPath = "Name"; 
            (e.DataFormItem as DataFormDropDownItem).SelectedValuePath = "Name"; 
            (e.DataFormItem as DataFormDropDownItem).LayoutOptions = LayoutType.Default; 
        } 
    } 
} 
 
 
public class CustomDropDownEditor : DataFormDropDownEditor 
{ 
    private DataFormItem dataFormItem;   
    public CustomDropDownEditor(SfDataForm dataForm) : base(dataForm) 
    { 
    } 
    protected override void OnInitializeView(DataFormItem dataFormItem, SfComboBox view) 
    { 
        base.OnInitializeView(dataFormItem, view); 
        if (dataFormItem.LayoutOptions == LayoutType.TextInputLayout) 
        { 
            this.dataFormItem = dataFormItem; 
            (view.Parent.Parent.Parent as SfTextInputLayout).IsHintAlwaysFloated = true; 
            view.SelectionChanged += View_SelectionChanged; 
            view.ShowClearButton = true; 
        } 
    } 
 
    private void View_SelectionChanged(object sender, SelectionChangedEventArgs e) 
    { 
        if ((sender as SfComboBox).Parent.Parent.Parent is SfTextInputLayout) 
        { 
            if (((sender as SfComboBox).SelectedValue != null && this.dataFormItem.ShowLabel == true) || ((sender as SfComboBox).SelectedValue == null && this.dataFormItem.ShowLabel == false)) 
            { 
                this.DataForm.RefreshLayout(true); 
            } 
        } 
    } 
} 
 
Please refer to the tested sample in the following locations. 
 
Please let us know if you have any concerns.

Regards,
SaiGanesh Sakthivel
 
 


Loader.
Up arrow icon