Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Validate different fields on click of different buttons in the same HTML Form through JQuery Validate Plugin

e.g. Say I have two textboxes A,B and two buttons C,D in a form. Then I want that on click of button C, if only textbox A is valid then form is valid, and on click of button D, if only textbox B is valid then form is valid.

Does anyone know how to do this?

like image 931
teenup Avatar asked Jan 26 '26 09:01

teenup


1 Answers

Use ignore option.

$("form").validate({ignore: ".ignore"});

$("#c").click(function(){
   //$("#a").removeClass("ignore");
   //$("#b").addClass("ignore");
   $(".step1").removeClass("ignore");
   $(".step2").addClass("ignore");
   $("form").valid();
});

$("#d").click(function(){
   //$("#a").addClass("ignore");
   //$("#b").removeClass("ignore");
   $(".step1").addClass("ignore");
   $(".step2").removeClass("ignore");
   $("form").valid();
});

EDIT: as outlined in my comment @dannie.f post

like image 114
Jules Avatar answered Jan 27 '26 22:01

Jules