0

I'm trying to add a CSS for the select field in simple form but it is not applying. I tried in the following ways,

= f.select :user_types, options_for_select([['Type', ''], ['College', 'admin'], ['Student', 'student']], {required: true, selected: ''}), input_html: {id: 'college_admin_type', class: 'form-control custom-drop-icon'}

= f.select :user_types, options_for_select([['Type', ''], ['College', 'admin'], ['Student', 'student']], {required: true, selected: ''}), wrapper_html: {id: 'college_admin_type', class: 'form-control custom-drop-icon'}

= f.select :user_types, options_for_select([['Type', ''], ['College', 'admin'], ['Student', 'student']], {required: true, selected: ''}), id: 'college_admin_type', class: 'form-control custom-drop-icon'

I found a similar kind of answer but unable to figure it. Here's a link Adding a css class to select in Rails.

1 Answer 1

3

If you are using simple_form you should use its as: :select notation

= f.input :user_types, as: :select,
  collection: [['Type', ''], ['College', 'admin'], ['Student', 'student']],
  input_html: { id: 'college_admin_type', class: 'form-control custom-drop-icon' }

But if you are using default rails select helper, you should pass html options as second options hash.

= f.select(:user_types, [['Type', ''], ['College', 'admin'], ['Student', 'student']], {}, { class: 'form-control custom-drop-icon' })

See also Ruby on Rails form_for select field with class

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.