javascript - Set all form field to invalid state: angularJS -
sure, can write like:
myform.price.$setvalidity('valid', true); myform.category.$setvalidity('valid', true);
and
myform.price.$setvalidity('valid', false); myform.category.$setvalidity('valid', false);
but want to function, , iterate via each field , set invalid state...
i tried so:
setvalidity = function(value, form){ _.each(form, function(field){ if (field.$dirty === undefined || !field){ field.$setvalidity('valid', value); } }); };
but doesn't work
maybe there approach of doing that?
i think using _ (underscore) apply array. should work with
for (fieldname in myform) { myform[fieldname].$setvalidity('valid', value); }
Comments
Post a Comment