Sonfaya
Sonfaya

Reputation: 65

how to disable the blank field in select rails

I'm trying to disable a field inside a select input. There is no problem for the standard field: (this disable the field 'one')

= f.input_field :job, collection: %w[one two three], disabled: 1, include_blank: 'Select one', required: true

What i would like to do now is to disable the blank field after a user selected an other field. I tryed this:

= f.input_field :job, collection: %w[one two three], disabled: 0, include_blank: 'Select one', required: true

But it didn't work... any idea ?

Thanks for your help and your time :).

Upvotes: 0

Views: 814

Answers (1)

Vasiliy Ermolovich
Vasiliy Ermolovich

Reputation: 24617

To disable blank value we use disabled: "" and to select it before user selects anything we use selected: "". Notice that it works with prompt option instead of include_blank only.

= f.input_field :name, collection: %w[one two three], disabled: "", selected: "", prompt: 'Select one', required: true

Upvotes: 1

Related Questions