Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery Form Validate() : How to setup default messages?

Until now, I've used jQuery validation plugin with previously defined fields. Now I'm working with a dynamic form. Fields have their validation needs mapped by its classes (e.g. " required "), but I don't see how to customize the messages jQuery validate throws.

like image 682
Victor Rodrigues Avatar asked Sep 03 '09 12:09

Victor Rodrigues


People also ask

How can I show error message below the textbox in jQuery validation?

Java scriptready(function() { $("#basic-form"). validate(); }); This is based on the assumption that you have already added the required JavaScript files. Adding those lines of JavaScript will make sure that your form is properly validated and shows all the error messages.

What is valid () in jQuery?

valid()Returns: Boolean Description: Checks whether the selected form is valid or whether all selected elements are valid.

Does jQuery validate require a form?

The jquery validate plugin requires a form element to function, so you should have your form fields (no matter how few) contained inside a form. You can tell the validation plugin not to operate on form submission, then manually validate the form when the correct submit button is clicked.


2 Answers

you can add your messages like so.

    $.extend($.validator.messages, {
        required: "your msg",
        email: "your email msg",
        digits: "your digits msg"
    });

See setDefaults

like image 183
Bjarki Heiðar Avatar answered Nov 06 '22 06:11

Bjarki Heiðar


$.validator.messages.required = "My new, default required message!";
like image 22
Craig Stuntz Avatar answered Nov 06 '22 05:11

Craig Stuntz