Is it possible to remove RequiredValidator

I've got a survey application that is using RadzenTemplateForm, most of the questions will be required to answer so there's a RadzenRequiredValidator component attached to the questions that are required.

The survey has subquestions, a question with single choice answer (radiobutton) will show subquestions that belong to that answer. So if it's a yes/no certain subquestions will show when "yes" is selected, same for "no".

Now it seems like when changing my answers it's validating every subquestion even though when rendering it's only showing the questions that belong to that answer.

//subquestions that should be shown based on answer
foreach (SubQuestion subquestion in question.SubQuestions.Where(q => q.ParentAnswerValue == question.AnswerValueString)) {
  <SurveyDisplayQuestion Question="subQuestion" />

and in the component I have a check on the Required property

@if (Question.Required)
    <RadzenRequiredValidator Component="@Question.Id.ToString()" Text="Vereist" Popup="false" Style="display: block;" />

In my testing I have a textarea required that shows when "no" is answered, a slider when "yes" is answered.

When I first clicked on "no", left the textarea empty and then clicked on "yes" to show the slider I wasn't able to submit the form because of the textarea being empty even though it's not rendering at all.

I've tried some stuff where I removed a component from the Form using the Validator to get the Form but doesn't seem to do anything (maybe I'm missing some kind of state change?), also put the Name of the component to an empty string if I didn't want to validate it but doesn't seem to do anything.

Hi @Grappig13,

I am afraid I don't understand what the problem is and couldn't get it from the provided code.

If you want to conditionally apply a validator you can try setting its Visible property to false.

Is there a way to get the validator from a specific RadzenFormComponent? It's definitely a weird situation, a change in a radiobutton selection impacts a change on subobjects. I've used a reference on the validator so far but that's specifically for that component itself.

No, there isn't a way to get a validator from a form component as they don't know about each other.

I found a way to get what I needed using the Visible property on the validator.

Thanks for the quick replies