basically you need to add confirmation for each element either by calling it by adding
myinput.className = "required"; // add this line
then add all your elements first before applying validation
or adding a rule
js("#EditCameraForm").validate(); rules: { camera_name: { required: true, minlength: 50, maxlength: 10 }, };
in this example, input with max. 50 char and min 10
you can also add custom validation with addMethod before you can validate
$.validator.addMethod("alphanum", function(value, element) { return this.optional(element) || /^[a-z0-9]+$/i.test(value); }, "This field must contain only letters and numbers."); js("#EditCameraForm").validate(); rules: { camera_name: { required: true, alphanum: true, minlength: 50, maxlength: 10 }, };
when the form is submitted, when you click the submit button, but donβt put a hidden place in it, just insert the validator handler
js("#EditCameraForm").validate(); rules: { camera_name: { required: true, minlength: 50, maxlength: 10 } }, submitHandler: function() {
Here is an example of how to apply custom messages, this will happen after the rules
messages: { email: { required: 'Enter this!' } }
l
mcgrailm
source share