Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding a bootstrap class to rails form time_select field

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?

like image 337
kpaul Avatar asked Nov 24 '25 11:11

kpaul


2 Answers

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' } %>
like image 171
srecnig Avatar answered Nov 27 '25 19:11

srecnig


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" %>

like image 34
7urkm3n Avatar answered Nov 27 '25 19:11

7urkm3n



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!