javascript - Adding own rule in jquery validation plugin -
i have next jquery code:
$("input").rules("add", { required: true, messages: { required: 'please enter telephone number' }, errorplacement: function(error, element) { console.log('bob'); element.insertbefore(error); } }); i trying add new rule in answer in question : jquery validation & id's ft numbers
have such html code:
<form method='post' action='' id='#countersform'> <input id="88" class="counter_input active" type="text" enabled=""> <input id="89" class="counter_input active" type="text" enabled=""> </form> my problems are:
1) why browser tries validate field on page loaded? don't need (message bob appeaing on page load.
2) why first input field validating? want validate fields.
3) why console says , element not defined?
documentation says element parameter contain validated element. console.log(element) says undefiened. why?
from documentation:
read, add , remove rules element.
it says 'an' element. $('input') in case returns 2 elements.
validation plugin uses name attribute of elements, element's doesn't have names.
you have initialize plugin using validate() method on form want validate, e.g.
$("#myform").validate({ //where form id of form rules: { name: "required", //name name of element }, messages: { } });
Comments
Post a Comment