serlingpa
serlingpa

Reputation: 12660

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.?

Upvotes: 4

Views: 6282

Answers (1)

Eliseo
Eliseo

Reputation: 57939

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()

Upvotes: 2

Related Questions