0

I'm using Jquery validator on a simple email input form.

<form name="form" submit.delegate="submit()">
    <div class="form-group">
        <label for="ea">Email</label>
        <input type="email" value.bind="emailaddy" class="form-control" id="ea" name="ea" />
    </div>

    <button type="submit" id="submitbutton"class="btn btn-default">Submit</button>
</form>

My validator rules are handling the required and valid email and my custom error messages show up correctly. On submit I want to check if the email already exists. The webApi call works but I don't know how to set the Jquery validator errorClass on my emailaddy element.

submit() {
    var vm  = this; 

    return vm.webApi.emailExists(vm.emailaddy)
        .then(function (data) {

            if (data === true) {
                console.log("email exists, don't submit");
                // set errorClass for the email element
            }
            else {
                console.log("email not found, submit");
                // do the submit
            }
        });
} 
evolver
  • 11
  • 2
  • Your code looks like AngularJS. If so, please refer to http://stackoverflow.com/questions/30410402/adding-class-to-element-using-angular-js – johnniebenson Jan 03 '17 at 20:22
  • it's plain Javascript, the question is only about setting the error class and validation state with Jquery validator. – evolver Jan 04 '17 at 11:03
  • I'm not entirely clear on what you're asking for. If you just want to add a class with JS: `document.getElementById("ea").setAttribute("class", "errorClass");` With jQuery it's: `$("#ea").addClass("errorClass");` – johnniebenson Jan 04 '17 at 15:00

0 Answers0