josefarias/hotwire_combobox

Are enums supported

HalfBloody opened this issue · 2 comments

Usually, I would use select_tags in my search forms like this:

= select_tag :platform, options_for_select(Device.platforms.keys, @platform), { include_blank: true }

I was wondering if the combobox would be a properly styled replacement for that? But I couldn't get it to work.

Edit:

Ok, I'm displaying it like this now:

= combobox_tag :platform, Device.platforms.map { |k, v| { "display" => k, "value" => v } }

But it's probably not intended to be used like that.

Thanks for the report!

I've been actively trying to sidestep needing an equivalent to #options_for_select. I think ideally you should be able to provide any acceptable kind of options collection to the #combobox_tag and it'll know what to do.

Currently, it'll know what to do with an ActiveRecord::Relation, an array of hashes (like you have now, which is correct), or a url/path helper.

We need to extend this behavior to intelligently handle enums, which I agree are a common use case. Would welcome a PR for this since I'm not programming for a few weeks – just reviewing on my phone.

One possibility that immediately comes to mind is that the combobox should be able to determine if it's received an array of strings and just use the string as both display and value. It'll be up to the user to titlecase/downcase the provided options as desired.

This will be supported in the next release. See PR for details: #35