I have a select menu that is a stimulus target. Each option of that select has a custom data attribute. When that select changes I need the stimulus controller to read a dataset attribute from the selected option...not the select menu target.
In the controller action, event.currentTarget is the select menu where the target attribute is set. Rather, I expecting it to be the selected option.
// this correctly returns the selected options value attribute. Stimulus must know what you want in this case.
event.currentTarget.value
// However, calling this returns the classList for the target...which is the select, not the option.
event.currentTarget.classList
// And, calling this returns 'undefined' because data-value is not defined on the target select, it's defined on the selected option...which is not the currentTarget.
event.currentTarget.dataset.value
So, when I call event.currentTarget.dataset.value in the stimulus controller I'm actually looking for data-value='xxx' from the selected option. But, instead stimulus is looking for data-value on the target select menu.
How would I return the 'xxx' data-value attribute from the selected option when the target menu is changed?