Hello,
I am using PlugIn in "http://bassistance.de/jquery-plugins/jquery-plugin-validation/".
I have different "Rules" assigned to different "Buttons" in a single form. I wrote below codes to assign rules to each button. When I click a button I need to make "removeClass" and rules("remove") to remove and clear all assignments made until that time. Then I need to make new assgnments.
1) Can you please advice the code to make this easier and faster?
2) Can you please advice if my way is correct in below code to to use different VALIDATEs in one form?
Thank you in advance.
- $("#button1").click(function() {
- $("#field3").removeClass("ui-state-highlight").rules("remove");
- $("#field1").rules("add", {required: true,minlength: 2,messages: {required: "Required", minlength: jQuery.format("Please, at least {0} characters are necessary")}});
- $("#field2").rules("add", {required: true,minlength: 2,messages: {required: "required", minlength: jQuery.format("Please, at least {0} characters are necessary")}});
- valid = $("#formum").valid();
- $("#buton2").click(function() {
- $("#field1").removeClass("ui-state-highlight").rules("remove");
- $("#field2").removeClass("ui-state-highlight").rules("remove");
- $("#field3").rules("add", {required: true,minlength: 2,messages: {required: "required", minlength: jQuery.format("Please, at least {0} characters are necessary")}});
- valid = $("#formum").valid();
- jQuery(function() {
- var v = jQuery("#formum").validate({
- errorLabelContainer: $("#hatamesaj"),
-
- submitHandler: function(form) {
- alert('SubmitHandler');
- },
- invalidHandler: function(form, validator) {
- alert('invalidHandler');
- },
- highlight: function(input) {
- $(input).addClass("ui-state-highlight");
- },
-
- unhighlight: function(input) {
- $(input).removeClass("ui-state-highlight");
- }
-
- });//validate
- });//function