[stimulusjs] Is it possible to pass param from select option to controller

Hi, as we know there’s a new cool param feature since ver 3. I wonder is it possible to pass somehow param when choosing select option. Like

<select data-action="change->visibility#toggle" >
   <option data-visibility-switch-map-param="daily" value="daily">Daily</option>
   <option data-visibility-switch-map-param="weekly" value="weekly">Weekly</option>
   <option data-visibility-switch-map-param="monthly" value="monthly">Monthly</option>
</select>

I’v resolved it temporary by just reading value from target like:

const switchMap = event.params.switchMap ? event.params.switchMap : event.target.value

, but wondered if it’s possible to do it without just pass param somehow.

No, this is not possible with a select element. Another alternative would be to get the option using

event.target.options[event.target.selectedIndex].dataset

But if the value is the same as data attribute, then your solution is better.

thanks, as expected but preferred to make sure :slight_smile: Yep, seems that event.target.value is set properly