jQuery Validate won't clear server-inserted error messages on KeyUp -
we using jquery validate plugin simple field validation. works expected when using default, client-side validation.
however, of these fields require server-side validation. problem occurs when manually creating error labels on server in html. when doing so, error label displays expected, behavior wrong.
essentially, once error label displayed, won't removed on keyup event of field. removed when press submit button, , first press of submit button hides error label , sets input field valid. have press submit button second time have form submit. appears jquery validate knows error label , it's connected input field, else wouldn't hidden when pressing submit button.
things i've tried:
- setting
generated="true"
on error label (no change) removing server-side label generation , returning error code creates label on client side validator object, yet behavior same (have press submit button first remove label , second time submit form):
var validator = $( "#form ).validate(); validator.showerrors({ "password": "invalid password" });
here example form server returned error label (using thymeleaf):
<div class="form-group"> <label for="password" class="ex-label" th:text="# {common.password}">password</label> <input id="password" name="password" type="password" class="form-control ex-input-modal required" /> <label th:if="${passfail}" for="password" class="error"> wrong password </label> </div>
title: jquery validate won't clear server-inserted error messages on keyup
it's not designed because it's client-side script.
the jquery validate plugin generates , toggles own validation error messages on client via javascript. since you're blocked submitting form server until jquery validate satisfied, not going see server generated validation messages in first place.
when used client-side validation, server-side validation messages never seen under normal conditions... server-side validation there protect in case javascript disabled, broken, or bypassed.
edit:
if you're trying evaluate whether email address, user account, or whatever in system, use plugin's built-in remote
method. rule use ajax()
call server-side script , if server-side script returns true
, rule passes validation. if script returns false
or json encoded string, rule fails validation. if use false
, default error message used. if return json string, "john smith in use", plugin use string error message.
Comments
Post a Comment