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.)