javascript - Form validation plugin fails with classes -
i working validator plugin have built, , each problem solved seems new 1 appearing. problem when use class validation selector, class validated , long 1 of them filled in accepted. now, while okay instances, not all.
fiddle
http://jsfiddle.net/9gwuyras/2/
the full code validation plugin can found in fiddle well.
parts of code think issue being caused
using fiddle reference lines of code lines 497 - 514
reasoning doesn't matter class selector in setting.selectors[] array multiple times, possible option.
for(var control in controls){ if(typeof controls[control] != 'object'){ console.log("controls."+control+" must object. skipping element"); continue; }else if(typeof controls[control].validate == 'undefined'){ console.log("controls."+control+".validate must defined"); continue; } $this.find('input, textarea, select').each(function(){ if($(this).is('#'+control)){ setcontroldata('#'+control, controls[control]); settings.selectors.push('#'+control); }else if($(this).hasclass(control)){ setcontroldata('.'+control, controls[control]); settings.selectors.push('.'+control); } }); }
lines: 397 401
reasoning might targeting form group of class selector , not focus
var formgroup = null; if(type != "radio" && type != "checkbox"){ formgroup = $(element).closest('.form-group'); value = $(element).val(); }
that's have far, continue post updates work through it. please request other information may needed. appreciated!
edit
i forgot important piece situation. how plugin called
$('#test').validator({ controls : { name : { validate : "notempty" }, dob : { validate : ['notempty', 'isdatetime'], dateformat : 'm/d/y' }, gender : { validate : "notempty" } }, bindinput : true, onsubmit : function(){} });
the keys in controls
object can either id or class name.
mark, i've read you're trying create plugin validates either id or class on form.
you stated: "the problem when use class validation selector, class validated , long 1 of them filled in accepted. "
this happening because once plugin triggered 'loops'(your each loop) through matching class...even if element wrapped in class filled out once(and there multiple other instances of it).
you have many options, recommendation either: 1)remove ability plugin call class or 2)validate class checking it's state. right go through , try validate when should validating class based on state(checked, unchecked, .val etc.).
hope makes sense.
Comments
Post a Comment