1

There is a switcher component from ux-components library that allows several events to be processed. One of those event handlers is called onValueChange. I want to prevent the default behavior and disable that event from triggering at all.

I tried some of the js methods, such as preventDefault(). It seems like it won't work with custom events.

This is my component that has the onValueChange event.

<ux-switcher-field 
  (onValueChange) = "someFunc()" >
</ux-switcher-field>

This is the event emitter:

@Output()
public onValueChange = new EventEmitter<UxValueChangeEvent<T>>();

And as I said, I want just to disable that event from triggering in one specific place.

ford04
  • 66,267
  • 20
  • 199
  • 171

2 Answers2

0

You can use event.preventDefault() like this in template

<ux-switcher-field 
  (onValueChange) = "$event.preventDefault()" >
</ux-switcher-field>
Barkha
  • 702
  • 3
  • 8
-1

You can use $event.stopPropagation() to cancel the event.

The code should look as bellow:

<ux-switcher-field 
  (onValueChange) = "$event.stopPropagation()" >
</ux-switcher-field>

more details about stopPropagation you can read here:

stopPropagation description

bat7
  • 836
  • 1
  • 8
  • 22