jquery validation issue with checkboxes -



jquery validation issue with checkboxes -

having problem jquery validation. have 2 checkboxes... on sec requiring checked.

the validation works, however, there 2 problems :

1 - if there error (2nd box not checked) removes <span> first totally unrelated it... still shows error message sec should.

2 - when there error on 2nd... checking not remove error message. also, checking , unchecking multiple times causes multiple error messages displayed on each 'uncheck'.

html :

<form id="downloadinstall" method="post" action="/process/p_module_dl.php"> <div class="row"> <div class="col-md-12 margin-bottom-30 form-group"> <p class="f-15 margin-bottom-15"><b>select options :</b></p> <div class="checkbox-list"> <label <input type="checkbox" name="settings[confirm]" value="1"/> <span>require confirmation during installation?</span> </label> <span class="help-block">notifies user software installed , requires confirmation before installed.span> </div> </div> <div class="col-md-12 margin-bottom-50 form-group"> <div class="checkbox-list"> <label for="vdownload-terms"> <input id="vdownload-terms" type="checkbox" name="settings[terms]" value="1"/> <span>i agree <a data-window="external" href="/terms.php">terms , conditions</a>.</span> </label> </div> </div> </div> <div class="row"> <div class="col-md-12 margin-bottom-50 form-group"> <button class="btn btn-primary" type="submit"><i class="fa fa-download"></i> download</button> </div> </div> </form>

js :

$('#downloadinstall').validate({ errorelement: 'span', //default input error message container errorclass: 'help-block', // default input error message class focusinvalid: false, // not focus lastly invalid input rules: { 'settings[terms]': { required: true } }, messages: { 'settings[terms]': { required: "you must agree terms , conditions before downloading." } }, highlight: function (element) { // hightlight error inputs $(element) .closest('.form-group').addclass('has-error'); }, unhighlight: function (element) { // un-hightlight error inputs $(element) .closest('.form-group').removeclass('has-error'); }, errorplacement: function (error, element) { error.insertafter(element.closest('.checkbox-list')); }, submithandler: function(form) { // other things valid form form.submit(); } });

update :

in case of sec issue. checking , unchecking checkbox causing has-error added/removed container, not remove <span> error message - adds another. thing happens color of error messages changes reddish when error class nowadays gray css style.

<div class="col-md-12 margin-bottom-50 form-group has-error"> <div class="checkbox-list"> <label for="vdownload-terms"> <div id="uniform-vdownload-terms" class="checker"> <span class=""> <input id="vdownload-terms" type="checkbox" value="1" name="settings[terms]" aria-required="true" aria-describedby="settings[terms]-error settings[terms]-error settings[terms]-error settings[terms]-error" aria-invalid="true"> </span> </div> <span>i agree <a href="/terms.php" data-window="external">terms , conditions</a>.</span> </label> </div> <span id="settings[terms]-error" class="help-block">you must agree terms , conditions before downloading.</span> <span id="settings[terms]-error" class="help-block">you must agree terms , conditions before downloading.</span> <span id="settings[terms]-error" class="help-block">you must agree terms , conditions before downloading.</span> <span id="settings[terms]-error" class="help-block">you must agree terms , conditions before downloading.</span> </div>

one thing did not notice until id beingness modified , appears due utilize of uniform plugin. uniform js

i able solve issue help/advice above...

//errorelement: 'span', //default input error message container errorclass: 'help-block f-13', // default input error message class focusinvalid: false, // not focus lastly invalid input

everything else same. commented out using span errorelement... defaults error messages showing in label eliminates issues had. added f-13 class errorclass styles font 13px (since messages in labels font size of labels larger).

end result looks , acts same minus problems.

jquery jquery-validate

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -