hotwired / stimulus

A modest JavaScript framework for the HTML you already have

Home Page:https://stimulus.hotwired.dev/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Many values for controller or value mapping can get verbose

paulodeon opened this issue · comments

I'm wrapping the https://tom-select.js.org/ library in stimulus and there are a lot of settings that I would like to set via data attributes. The problem is that this gets verbose very quickly

<%= f.select :covering_id_in, Employment.for_select, {}, { multiple: true, data: { controller: "tom-select", tom_select_color_value: "slate", tom_select_auto_submit_value: true, tom_select_placeholder_value: "Select instructor" } } %>

That's only with three values - the problem is that every value name is wrapped by controller_name_#{value_name}_value

A workaround is to pass an entire object which works but doesn't auto camelize the keys or provide default values

<%= f.select :covering_id_in, Employment.for_select, {}, { multiple: true, data: { controller: "tom-select", tom_select_settings_value: { color: "slate", auto_submit: true, placeholder: "Select Date Range" } } %>

Any suggestions for a better way of doing this would be appreciated!