Rails: Disable options of a select field

Posted . Visible to the public.

Simply give the select helper an option :disabled, passing either a single value or an array. You need to specify the option's value, not its text.

= form.select :country, Address.countries_for_select, :include_blank => true, :disabled => ['disabled-value1', 'disabled-value-2']

Also see Cucumber: Check if a select field contains a disabled option on how to test this.

Dominik Schöler
Last edit
License
Source code in this card is licensed under the MIT License.
Posted by Dominik Schöler to makandra dev (2013-08-02 06:42)