views:

39

answers:

2

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

+1  A: 

I don't know why on earth you would want to put radio buttons in a drop down list. That sounds confusing to users. Why not just select the drop down option the normal way? Is this a business requirement?

If you absolutely have to do it, I think option 2 is the best one you've presented, although I don't know if it needs to be an option in the drop down list. It might work better as a link or a button next to or under the list. The list and the link (or button) should be in a containing div so that the corresponding drop down is easy to find, in the event that you have multiple drop downs like this on the page. From there it's easy enough to attach some javascript to the link (or button) which will deselect all radio buttons in the list.

But I still suggest that having radio buttons in a drop down list is just bad design from a user's perspective and I have no idea what this would accomplish.

Samo
I'm maintaining a project where it looks like that right now, and I agree that it's confusing. Question: If I remove the radiobuttons, and go with a 'normal' dropdown-list instead, will it be easier to deselct all options? Because thats the functionality that I'm after.Thanks for your tips!
Emil
Your question gives me the impression that multiple items in a drop down list are selected, which doesn't seem possible. Is this the case, or are you talking about deselecting options from all drop down lists? Either way, I think it's equally easy to deselect all radio buttons as it is to deselect all drop down options on a page, but the drop downs would have to have a default value (i.e. "Select a value") so that you can set the selectedIndex to 0. So maybe $('select').each(function() { this.selectedIndex = 0 }) (my syntax may not be exact)
Samo
Keep in mind that my previous comment assumes you're using jQuery. If you're using prototype it is similar but probably slightly different. I haven't used prototype in quite a while so you will have to check the API.
Samo
+1  A: 

Radio buttons are meant to choose something out of a group of options. Any time I see a group of radio buttons with none selected, I think whoever designed it doesn't understand radio buttons. Maybe you need to add a "None of the above" radio button?

davidkovsky