how to detect formly toggle field type is disabled?

Discussão em 'Angular' iniciado por Ramses Kouam, Agosto 7, 2025.

  1. Ramses Kouam

    Ramses Kouam Guest

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

    Continue reading...

Compartilhe esta Página