Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ControlValueAccessor and touched

I have implemented a date picker using three drop downs for date, month and year. The date picker is a component that implements ControlValueAccessor and is working great. However, I would like the control to expose touched when any of the three drop downs are touched.

There are lots of questions about related issues regarding touched, but not this specific issue which seems odd to me since it's something you would want to do by default!

How do I expose a touched state of my component? Additionally, how about pristine, dirty etc.?

like image 690
serlingpa Avatar asked Oct 25 '25 13:10

serlingpa


1 Answers

Only for touched: If your component extends of ControlValueAntecesor you have some like

//declare two functions onChange and onTouched
onChange;
onTouched;
//register onChange and onTouched
registerOnChange( fn : any ) : void {
    this.onChange = fn;
}

registerOnTouched( fn : any ) : void {
    this.onTouched = fn;
}

The only thing you need is, when you change one dropdown call to the function

this.onTouched()
like image 191
Eliseo Avatar answered Oct 27 '25 01:10

Eliseo