无法在简单形式 select 中添加 css class
Unable to add css class in simple-form select
我正在尝试以简单形式为 select 字段添加 CSS,但它不适用。我尝试了以下方法,
= 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'
我找到了类似的答案,但无法理解。这是 link .
如果您使用的是 simple_form
,则应使用其 as: :select
表示法
= f.input :user_types, as: :select,
collection: [['Type', ''], ['College', 'admin'], ['Student', 'student']],
input_html: { id: 'college_admin_type', class: 'form-control custom-drop-icon' }
但是如果您使用默认的 rails select
助手,您应该将 html 选项作为第二个选项散列传递。
= f.select(:user_types, [['Type', ''], ['College', 'admin'], ['Student', 'student']], {}, { class: 'form-control custom-drop-icon' })
另见 Ruby on Rails form_for select field with class
我正在尝试以简单形式为 select 字段添加 CSS,但它不适用。我尝试了以下方法,
= 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'
我找到了类似的答案,但无法理解。这是 link
如果您使用的是 simple_form
,则应使用其 as: :select
表示法
= f.input :user_types, as: :select,
collection: [['Type', ''], ['College', 'admin'], ['Student', 'student']],
input_html: { id: 'college_admin_type', class: 'form-control custom-drop-icon' }
但是如果您使用默认的 rails select
助手,您应该将 html 选项作为第二个选项散列传递。
= f.select(:user_types, [['Type', ''], ['College', 'admin'], ['Student', 'student']], {}, { class: 'form-control custom-drop-icon' })
另见 Ruby on Rails form_for select field with class