Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
2225
Issue with validation of hidden editors.
posted

I have a form in which there are two sections.

There are three possibilities for how it is displayed and they are:

  1. Section1 Visible, Section 2 Hidden
  2. Section 1 Visible, Section 2 Visible
  3. Section 1 Hidden, Section 2 Visible

There are editors in both sections that have the following settings:

.Required(true)
.ValidatorOptions(m => m.OnSubmit(true).KeepFocus(ValidatorKeepFocus.Never).FormSubmit(true))

The issue is that they shouldn't be validated if they are hidden. However, I'm seeing that the hidden fields ARE showing the red "This field is required" message when the form is submitted. It shows up in the very top left corner of the screen and isn't associated with any field visible on the screen.

I am using:

  • DatePicker
  • TextEditor
  • CurrencyEditor

The current required message is from a textEditor item.

How can I set the editors to ignore the "Required" flag when hidden on the form?

Thanks,
Tony

FYI, I am hiding the section with jquery, similar to this:

<script type="text/javascript">
    $(document).ready(function () {
        var condition1 = @Model.ID1;
        var condition2 = @Model.ID2;

        if condition1 == 0) {
            $(".Section1").hide();
        }
        if condition2 == 0){
            $(".Section2").hide();
        }
     });
</script>

 

Parents Reply Children