Conditional Validation

Is it possible to make validation conditional? For example, if I have a dropdown and a text box on a form field and a certain value is selected in the drop down then I want the text box to be required; otherwise, if that specific value is not selected from the drop down then the text box would not be required.

Thank you.

1 Like

The easiest way for this most probably is to have two sets of input components (with and without validation) and set Visible depending on a condition.

What we are seeing is that controls that we hide that have a validator the validation still fires even though the control is hidden. Is that expected behavior?

Hello Radzen Team!

It would be nice to have the validators not fire if they are not visible. I have several registration fields that are conditionally required depending on another registration field, and having duplicated components as suggested by @enchev is not an option for my supervisor.



Hi @kim,

It is already possible to set Visible=False to the validator component to skip the validation:

Visible property can be set to expression as well.


Dear @enchev,

Could you please check this method again. Unfortunately, can't stop the validation by hiding the validators.


This is not working anymore. In fact there are some weird logic going on with the RequiredValidator component. It's currently ignoring the Visible property and always validating no matter what. But also when Visible is set to an expression it applies in runtime, but then it will trigger the validation when the result is false.


Indeed the validation won't trigger only when put inside @if block at the moment.

@if (condition) {
   <RadzenRequiredValidator />

We will add support for the Visible property with the next Radzen release.


Did this make it into production?

Still recommend this method of coding for conditional validation?

Yes, the Visible property has been implemented for some time already. There is also RadzenCustomValidator.

1 Like