Setting data attribute in input

Hi, please i have a select field and I want to be able to use data-placeholder attribute for select2 but I got an error.

<%= multiple_select f, :selection_id, selection_list(), required: "required", data-placeholder: "Placeholder value" %>

Please what is the best way to do this?

I found the solution.

<%= multiple_select f, :selection_id, selection_list(), required: "required", data: [placeholder: "Please choose value"] %>

Thank you.

1 Like

Can also use data_placeholder: "Placeholder value" or "data-placeholder": "Placeholder value" too. :slight_smile:

I actually did not know about the embedded list format, that is fascinating, I know just where I can use that too (all my unpoly declarations). :slight_smile:

2 Likes

Thanks so much. i tried this "data-placeholder": "Placeholder value" earlier but it didn’t work (Phoenix 1.3). I will try the other option as well when i have a moment.

Thanks you immensely for your response.

Hmm, I tried it here and it worked, I’m not sure why it would not work, what error?

Do note that atoms with underscores in the normal phoenix template stuff gets the underscores converted to dashes (I’m not sure how to prevent that actually), hence why data_placeholder: "Placeholder value" should work. :slight_smile:

Pardon me please, i guess i didn’t take extra care in validating this. I once tried it today but for some reasons it didn’t work. However i’ve tried it again and it’s working fine. Also the first option you highlighted also work great too. Thank you so much!

I’m glad i’ve learnt several ways to approach this! I really appreciate your time.

1 Like

I imagine you do not know that the embedded format is, uh, let’s say, very "ruby/rails"y (but I won’t tell anyone you said it was “fascinating”, do not fear)

Lol, well that format seems completely reasonable, just not immediately intuitive, though I would not expect it to add in a dash automatically but it does, so… ^.^

I actually had to rewrite my own input for some things as I had to specify attributes that ‘did’ actually have underscores in them, that was a pain, I wish it did not do the auto-conversion since it is easy enough to just do something like "data-blah_bloop": ... anyway. ^.^;