Hide / Show Form Items based on Dropdown Value

Hi there.

I'm having a problem dynamically changing the form based on the value of a dropdown.  I have a form that includes a Country field, which can be set to Canada or United States.  If Canada is selected, I want the Postal Code field to be visible.  If United States is selected, I want the Zip Code field to be visible.  I am using Data Annotations for validation, and the validation is different for Postal Codes and Zip Codes.


I have set a function to run on the Country dropdown's ValueChange event (this function also sets the selection of Provinces/States) to change a boolean of "ShowZipCode" depending on whether or not United States was chosen.  My DataForm itself has an if condition based on that boolean.  If ShowZipCode is true, then the ZipCode field is shown.  If not, the PostalCode field is shown.  The function ends by calling StateHasChanged. 


Simple, right?

Unfortunately, the result of this is that when the re-render is done, the field that should be hidden remains.  That is, the form is initialized with Canada as the Country value, with the PostalCode field showing.  Choosing United States results in the Zip Code field showing (intended behaviour) but with the Postal Code field remaining on the screen.  In fact, choosing back and forth between the two countries will result in MULTIPLE instances of each field, which is not what I'm looking for.


Any thoughts?  Is there another way I should be approaching this?  I'm on version 32.1.19.

I may have to re-approach the whole thing, as the validation for the child object (the address) does not seem to be being used at all.  (The class for the form includes a child class for the street address part, which in turn contains the DataAnnotation validation for the Postal Code and Zip Code fields - but it's not getting called at all, which is disappointing.)






1 Reply

SM Suresh Masanam Syncfusion Team December 30, 2025 01:48 PM UTC


We have already considered your requirement "Need to provide support for conditional rendering for the Form itemas a feature from our end, but we do not have any immediate plans to implement this feature. At the planning stage for every release cycle, we review all open features and implement them based on feature rank, customer request count, and volume wish-list.

 

The status of implementation can be tracked through the feedback portal link below:

 Need to provide support for conditional rendering for the Form item in Blazor | Feedback Portal 


Note: By closing this forum today, we are directing you to our feedback platform for future correspondence regarding feature requests, allowing our technical team to engage with your input directly. Be assured that closing the forum does not affect our commitment to considering your suggestion.



Loader.
Up arrow icon