How to hide/show form items in a data form depending on the value of the dropdown list?

Is there a way to hide or show form items in data form depending on the selected value in a dropdown list? The dropdown list is also part of the data form.



3 Replies

UD UdhayaKumar Duraisamy Syncfusion Team January 28, 2025 05:16 PM UTC

To dynamically hide or show Form items in the DataForm component based on the value selected in a Dropdown List, you can utilize Form Items, Templates, and conditional rendering.
  1. Conditional Rendering: Use conditional statements (like if or @if in Blazor) to determine which form items should be displayed based on the selected value in the dropdown list.
  2. Templates: You can leverage templates for further customization of the form items.
  3. Custom Validation: If the dynamically rendered form items require validation, you can implement custom validation to ensure proper functionality.
For detailed implementation steps, please refer to the following resources:


EA Eunice Ariola January 31, 2025 03:41 AM UTC

Thank you for your response. But how can you call the form items in the code section to setup custom validation?

I see some examples using EditForm but i don't see demos for Syncfusion's data form.



YV Yaswin Vikhaash Rajaretenam Syncfusion Team February 3, 2025 01:31 PM UTC

Hi Eunice Ariola,

Thank you for reaching out. We have validated your query and found a solution. Custom validation in Syncfusion Blazor DataForm allows you to define your own validation rules by creating a custom ValidationAttribute and applying it to form fields.

For detailed instructions and an example, please refer to the documentation and sample provided below.

https://blazor.syncfusion.com/documentation/data-form/data-annotation-attributes#custom-validation

If you have any further questions, feel free to ask!

Regards,

Yaswin Vikhaash


Attachment: SFDataform_validation_1ede565d.zip

Loader.
Up arrow icon