Trigger select change


#1

hi everyone,
My select change trigger configuration
data-action=“change->category#categoryChanged”
and in my controller I have the categoryChanged method created, but my select can be changed programmatically. So I’m wondering if Stimulus have the onChange event how can I trigger it without create a new javascript eventListener.

thanks and advance.


#2

I was able to do this by doing element.dispatchEvent(new Event(‘change’))
Hope it helps


#3

I end up with this solution

[name]Target.dispatchEvent(new Event('change'));

It seems like that Stimulus create the eventListener based on naming conventions, i.e, you can trigger the events by their stimulus name.


#4

you edited your answer while I was posting my answer, but yes, that was my solution too


#5

yeah, thanks :slight_smile: