Adding trips to specific selections in simple_form

The user can select 5 options. Once they select one, they cannot select it again. Currently, I'm just deleting previously used parameters from the list ... so they can only select from previously unused ones. The only thing I don’t like about this is that when a user adds a new record to the database, they may wonder why there are no parameters in the list.

One of my ideas was to leave the previously used options in the list, but cross them out and make them disabled.

Is it possible to disable (and / or add a class) only certain parameters in an element? Simple_form seems to have an option_html helper, but it has not been documented.

+4
source share
2 answers

It turns out it's easy to do. Rails supports it ...

<%= f.association :ying, collection: @yangs, :disabled => @used_yangs %> 
+7
source

It only works for me when I pass identifiers to a disabled option. Like this:

= f.association :stuff, disabled: Stuff.where(enabled: false).map(&:id)

Using Rails 4.2.3

This applies correctly to Rails documents. Check :disabled description here: http://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html

+1
source

Source: https://habr.com/ru/post/1487193/


All Articles