Question

I have rule:

cmp_email: {
                        minlength: 5,
                        required: true,
                        email: true,
                        remote: {
                            url: "\/client\/check-email",
                            type: "post"
                        }
                    },

And for remote rule I want to place an error message: "This email already exist" inside alert-error class. Is this is possible with jQuery validation plugin ?

Was it helpful?

Solution

It is possible, yes, using the messages option to jQuery Validate.

$('form').validate({
  rules: {
    cmp_email: {
                    minlength: 5,
                    required: true,
                    email: true,
                    remote: {
                        url: "\/client\/check-email",
                        type: "post"
                    }
                },
  },
  messages: {
    cmp_email: {
      remote: "This email already exists"
    }
  }
});

OTHER TIPS

Yes it is possible. To do this you will need to have your options for the validation plugin setup in a similar manner.

rules: {
    cmp_email: {
        minlength: 5,
        required: true,
        email: true,
        remote: {
            url: "\/client\/check-email",
            type: "post"
        }
    },
},
messages: {
    cmp_email: { 
        remote: "This email already exist"
    }
}
errorClass:"alert-error"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top