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. ^.^;