angular - Angular2 Custom Component - mark as pristine and untouched -
i have template driven form in angular 2.1 containing many standard controls (<input>, <select>
etc) , custom control contains multiple input elements.
i've implemented controlvalueaccessor on custom control , propagating it's changed/touched/valid values correctly parent form.
however .. on parent form have save button, on after saving want clear dirty/touched state (as affects css applied) this:
save(myform: ngform) { myform.form.markaspristine(); myform.form.markasuntouched(); }
this working ok elements in top level parent form , custom control but <input>
fields within custom control still marked touched/dirty (and receiving pre-saved styling).
is there way custom control can notified when it's dirty/touched state changed can clear it's child <input>
elements match? seems if <input>
elements within custom control don't updated calls markaspristine/untouched on parent form.
thanks!
try add controls['nameofcontrol']
this
myform.form.controls['nameofcontrol'].markaspristine();
the code above work form controls.
the following seems work around:
active = true; newmodel() { this.model = new yourmodel(2, '',true, ''); this.active = false; settimeout(() => this.active = true, 0); }
reset form new model , restore 'pristine' class state. toggling 'active' flag cause form removed/re-added in tick via ngif. yes small work around until can can fix :)
hope helps
Comments
Post a Comment