I have a formly form with toggle field, I would like to detect when the user clicks on the toggle to disable it. here is what I have done so far:
fields: {
key: myToggle,
id: myToggle,
templateOptions:{
label: myToggle
}
hooks:{
onInit: (field) =>{
field.formControl?.valueChanges.pipe(
filter(e=>
e['property'] === 'model.myToggle' && e['type'] === 'expressionChanges'
),
tap(performAction)
)
}
}
}
I also tried this solution in the ngOnInit() method:
this.form.valueChanges.pipe(
takeUntilDestroyed(this.destroyRef)
).subscribe(() =>{
perFormMyActionWhenFalseValueIsDetected();
}
With the second solution, the method is called as times as the form field number. If I have 3 fields, the method will be called 3 times. How can you do specifically detect the event toggle field is set to false?