user154537
user154537

Reputation:

jquery validation plugin minLength override in invalidHandler

Is it possible to override the default minlength error message in the callback invalidHandler ?

Say by default the error message for minlength would be Please enter at least {0} characters. Can this be overriden with the inclusion of the form element say {element} - Please enter at least {0} characters. validator.numberOfInvalids() is able to capture this error but am not able to figure out how to override the error message of the corresponding error.

Any help in this context is really appreciated, Thanks.

Upvotes: 1

Views: 592

Answers (2)

cregox
cregox

Reputation: 18408

this:

$(".selector").validate({
     rules: {
          name: {required: true, minlength: 4}
     },
     messages: {
          name: {required: $(this).id + "error message", minlength: "name too short"}
     }
})

Upvotes: 0

idrumgood
idrumgood

Reputation: 4934

See this page for the document ion. I think what you want is to set a message option.

$(".selector").validate({
     rules: {
          name: "required"
     },
     messages: {
          name: {
             required: $(this).id + "error message"
          }
     }
})

Can't test this right now, but this is what I would try.

Upvotes: 1

Related Questions