javascript - Enable ASP.Net validator without immediately running validation -


question

can enable asp.net validator without running validation (i.e. giving user chance input values before running it, still force running validation on form submit)?

background

i have form allows person input family data when check in child(ren) public daycare system. have 5 fields need force parents actively consider (allergies, special needs, etc). values not required, many parents skipping on fields when children should have had values specified.

my solution have required field validator that's disabled if click n/a checkbox next textbox. (if has better solution, i'm ears; ui of form--which inherited--makes me want gouge out eyes.)

the other thing when "add family" button clicked, 4 empty rows auto-generated: 2 adults , 2 children. whether row represents child or adult determined drop-down in row. if "adult" selected, or if first name textbox in row empty, validators disabled.

the validators of 5 fields enabled both drop-down selected value "child" , first name textbox not empty. issue running validatorenable() causes form validate. in common case, fields empty, since first name , "family role" (adult/child) inputted before whether person has allergies or potty trained. means input name row specified child, asp.net's "hey, dummy, have invalid field!!!1!".

so, enable validator, prevent validation until user either inputs empty value allergy textbox, or try submit form.

is possible?

note, use custom field validator, validation isn't run on empty fields; afaik, required field validators that.

i've adapted answer here: http://veskokolev.blogspot.co.uk/2007/11/how-to-disable-validation-group-with.html enable validators client-side jquery. once enabled, validation function did run - don't know how stop (without modifying asp.net js code, guess option?); hid messages until validation run again (which easy enough $(x).hide()).

considering client-side code show warning , stop submitting think ok. usual things cause validator re-run re-show message.

so if have validators like:

<asp:validator runat="server" cssclass="js-validator-set-a" /> 

i can use javascript:

togglevalidators('.js-validator-set-a', true);      function togglevalidators(selector, enable) {     // page validators jquery object     var vals = getjqueryobjectfromarrayofels(page_validators)      vals.filter(selector).each(function (i, o) {         validatorenable(o, enable);         $(o).hide();     }); };  function getjqueryobjectfromarrayofels(elsarray) {     var x = $();     $.each(page_validators, function (i, o) {         x = x.add($(o));     });     return x; } 

Comments

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -