Adding a bootstrap class to rails form time_select field

佐手、 提交于 2021-01-27 12:26:59

问题


Bootstrap has the class 'form-control' to add to select boxes to give them styling. I was able to do it successfully so for the following field:

 <%= f.collection_select :team_a_id, @teams, :id, :name, {prompt: "Select first team"}, {class: "form-control"} %>

However I have the following form field for time_select. I need to apply an html class(preferably "form-control") to the following form field and have not been successful in doing so with the same approach above.

 <%= f.time_select :match_time, prompt: {hour: 'Choose hour', minute: 'Choose minute'}, minute_step: 15 %>

How would I approach this problem?


回答1:


The html_options is the third parameter, as described in the docs:

time_select(method, options = {}, html_options = {})

so something like this should work:

 <%= f.time_select :method, { prompt: {hour: 'Choose hour', minute: 'Choose minute'}, minute_step: 15 }, { class: 'form-control' } %>



回答2:


From DOCs

time_select(object_name, method, options = {}, html_options = {})

Probably you are looking smth like this:

<%= f.time_select :match_time, '', {prompt: {hour: 'Choose hour', minute: 'Choose minute'}, minute_step: 15}, class: "form-control" %>



来源:https://stackoverflow.com/questions/37353083/adding-a-bootstrap-class-to-rails-form-time-select-field

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!