Scenario: I have a dropdown-list with radiobuttons, that are not required to be selected to submit the form, and after I've chosen an option, from there on it's impossible to deselect it. I want it to be possible somehow.
Thoughts for solutions: 1) Implement some feature that enables you to deselect the radiobutton, much like a checkbox. This seems like a poor idea.
2) Add a 'reset radiobutton' option in the dropdown-list, that resets the radiobuttons when selected.
3) Add a 'reset all radiobuttons' button. Possibly for all dropdowns on the page.
4) Create a 'placeholder' option in the dropdown-list, that does nothing. The question here is, if I already made a selection X and submitted the form, if I later on choose selection Placeholder, any data that was saved when selection X was made has to be reverted.
So far I'm thinking option 2 is the best, but want to hear your ideas. This is the code that I'm working with right now:
<% form.inputs do %>
<% @account.account_preference.editorial_attributes.each do |key, value| %>
<%= account_pref.input "editorial_#{key}".to_sym, :as => :radio, :collection => (options_for(Editorial, key.to_sym) + option_text_and_value("Reset radiobuttons")), :wrapper_html => { :class => "compact" }, :label => key.titleize %>
<% end %>
Where options_for(Editorial, key.to_sym) collects the options that actually do something, and option_text_and_value("Reset radiobuttons") is supposed to add another option that I then can link to the functionality to uncheck the radiobuttons. This doesn't quite work as expected, as option_text_and_value returns two options instead of one. I have tried to search for some other option method on apidock but haven't found one yet. This isn't the primary question but if anyone knows about this and comments I'd be very grateful.
So to wrap it up: What way to go do you think is the best?
Regards, Emil