1

I have a model that has two fields that use the RequiredIf validator (either Phone or Email is required):

[RequiredIf("Phone == null", ErrorMessage = "Either Phone or Email is required")]
public string Email { get; set; }
[RequiredIf("Email == null", ErrorMessage = "Either Phone or Email is required")]
public string Phone {get; set; }

The issue is that on the form, if you tab to the first field (Email), as soon as you tab to it, the validation for Phone fires and the error message shows up. If you start typing, the error message disappears.

The requested functionality is that if you tab into Email, the validation not fire until you tab out of both conditionally required fields, or alternatively, that the validation not fire until you click the submit button.

Is this possible using the RequiredIf annotation?

JeffCren
  • 396
  • 1
  • 5
  • 15

1 Answers1

0
    <script>
        ea.settings.apply({
            dependencyTriggers: null // fire validation on submit only
        }); 

        ea.settings.apply({
            dependencyTriggers: 'keyup' // fire on keyup
        }); 

    </script>

more info https://github.com/jwaliszko/ExpressiveAnnotations#how-to-control-frequency-of-dependent-fields-validation

Ivan R
  • 51
  • 1
  • 4