Pynnie
Pynnie

Reputation: 136

How to make a drop-list selection mandatory excluding the blank value

In my code, i have the following drop list

<%= f.collection_select :manufacturer_id, @manufacturers, :id,
            :name,{include_blank: "Select manufacturer",  required: true}, {class: "form-control"} %>

Somehow the blank is accepted as a selection. Is there a way to prevent this? I want the user to select a value form the drop-list, except for the blank.

Thanks for the help!

Upvotes: 0

Views: 34

Answers (1)

Jacob Vanus
Jacob Vanus

Reputation: 569

Required is an html parameter. Try:

<%= f.collection_select :manufacturer_id, @manufacturers, :id,
            :name,{include_blank: "Select manufacturer"}, {class: "form-control",  required: true} %>

Upvotes: 2

Related Questions