Make Property IsVisible of DataFormItemBase bindable

Very commonly I come across need to toggle visibility of certain form items based on the value set to other items.

For example: if i need to ask user two questions, but type of second question would depend on the response to the first question. and do all that via SfDataForm data binding?

My approach would be to have all possible questions available in the form, but hidden by default and only appear when user makes selection of the first question.


1 Reply

KA Karthikraja Arumugam Syncfusion Team March 3, 2020 11:10 AM UTC

Hi Vadim, 
 
Thank you for contacting Syncfusion support. 
 
Based on the shared information we have checked your requirement of “Changing the visibility of DataFormItems in runtime based on another field value” and it can be achieved inside PropertyChanged event of DataForm’s DataObject, in PropertyChnaged event handler get the changed property value and based on that you can change the visibility of a DataFormItem. To get a DataFormItem in runtime use ItemManager class DataFormItems method. 
 
Please refer the following code snippet for the same, 
(dataForm.DataObject as ContactsInfo).PropertyChanged += DataFormBehavior_PropertyChanged; 
 
  private void DataFormBehavior_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) 
 
            var dataobject = sender as ContactsInfo; 
 
            if(e.PropertyName == "Password" && dataobject.Password != null) 
            { 
                var dataFormItem = dataForm.ItemManager.DataFormItems["ConfirmPassword"]; 
                dataFormItem.IsVisible = true; 
            } 
   
 
We have prepared a sample for the same, in our sample we have changed ConfirmPassword field visibility after editing the Password field. 
 
Sample link: DataFormItemVisibility 
 
We hope this helps. Please let us know if you have any concern. 
 
Regards, 
Karthik Raja A 


Loader.
Up arrow icon