javascript - validating single set of fields on click using Jquery validate -
ive made form has several sections, later sections hidden displayed after user clicks next button on current section. im trying simple "must filled" validation on click before rest of form displayed.
as far can gather other questions on here method should work.. var validate
should equal true
if errors found stop form progressing allow form progress once fields have been filled , button clicked again
however seems @ moment validate first field , nothing. if field valid still not progress rest of actions on function.
js library : http://cdn.jsdelivr.net/jquery.validation/1.14.0/jquery.validate.min.js
method im trying use: http://jqueryvalidation.org/validator.element/
<div class="col-sm-8 sec-one"> <div class="form-group"> <select name="t1" required> <option value="" disabled selected>choose option...</option> <option value="b">b</option> <option value="c">c</option> <option value="a">a</option> <option value="d">d</option> </select> </div> <div class="form-group"> <select name="t2" required> <option value="" disabled selected>choose option...</option> <option value="a">a</option> <option value="d">d</option> <option value="b">b</option> <option value="c">c</option> </select> </div> <button type="button" class="formbut next1">next</button> </div> var validator = $("form").validate(); $(".next1").click(function () { validator.element('.sec-one [name]'); if (validator) { $(".sec-one").slideup("slow", function () { $(".sec-two").slidedown("slow"); }); } else {} });
"as far can gather other questions on here method should work..
var validate
should equaltrue
if errors found"
i'm not sure saw that. in code, you've dropped element()
part conditional. , $('#yourform').validate().element()
supposed return true
if there no errors.
var validator = $("#myform").validate(); // create validator variable validator.element("#myselect"); // test element
better way...
refer official website , use the .valid()
method test form and/or individual elements. true
indicates no errors.
$('#myform').valid();
or
$('input[name="myelement"]').valid();
Comments
Post a Comment