-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding extra HTML to select options #1575
Comments
Hi @AJFaraday, thanks for the issue. This would be a feature request. Simple Form uses just the first and second item from each item from the given array. In this case, you only can choose the item that will be the label and/or the value using the options https://github.com/plataformatec/simple_form#collections More info in the code: I'm not sure how we could handle that. Could we consider that items from the third position are HTML attributes? 🤔 |
Hi @feliperenan Thanks for getting back to me! It's a while since I was looking into this. I wound up dropping back to the rails form helpers and wrapping it in an There was another use-case for this recently, when I was selecting from a list of named CSS colors, and adding a style attribute to each |
Closing this since it's possible to pass html options to every select's option. See a test case for this here |
@nashby I didn't get that to work for whatever reason. Here is an alternate way to still use Simple Form wrapping in conjunction with the Rails select helper to achieve this:
<%= l.input :color_thickness, label: 'Type' do %>
<%= l.select :color_thickness, options_for_select([['Blue 3/4"', {'data-price': 0.33} ], ['Blue 1"', {'data-price': 0.43 }]]), { include_blank: true }, { class: "form-control select optional width-100" } %>
<% end %> |
I can't see a way to do this, with extensive googling and a look through the simple_form code base. Perhaps I'm missing something. I want a select field, with an extra 'data-' attribute in the options. I can do it, but only at the expense of losing a separate value field.
The data I'm trying to present:
Case 1:
This presents options with the first option as both the visible option and the value attribute. It does, however, include the description on them both.
Case 2:
This presents the numeric id as the value attribute for the options, but the data attribute has disappeared.
case 3:
Exactly the same result as case 1, the value attribute is the name field.
This might be a feature request, or just a request for help using the library. Is there any way to define my own attributes, and add extra html attributes to the options?
The text was updated successfully, but these errors were encountered: