Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding disable to certain select options in simple_form

A user can chose 5 options. Once they choose one, they can not choose it again. Currently, I simply remove previously used options from the list...so, they can only choose from previously unused ones. The only thing I don't like about this is that as the user is adding a new record to the database, they might wonder why options seem to be missing from the list.

One idea I had was to leave previously used options in the list but cross them out and make them disabled.

Is it possible to disable (and/or add a class) to only certain options in a select? Simple_form seems to have an option_html helper but, didn't see it documented.

like image 898
hellion Avatar asked Jun 20 '13 03:06

hellion


1 Answers

Turns out this is quite easy to do. Rails supports it...

 <%=  f.association :ying, collection: @yangs, :disabled => @used_yangs %>
like image 144
hellion Avatar answered Oct 22 '22 07:10

hellion