I stumbled on the select box while creating an application with rails, so I will keep it as a record.
The environment is as follows. ruby 2.6.5 Ruby on Rails 6.0.3.
Originally, the select box for business hours has already been implemented.
Add a button that is open 24 hours a day + I want to make sure that '00' is entered in all select boxes when the button is clicked using Javascript. (The image below)
Class name is not given to select attribute! I was thinking of proceeding in the following order, but my nose was brilliantly crushed.
For the time being, I rewrote it with the following code to give a class name. (Write class: "opening-hour"
at the end of {})
<%= f.time_select :open_time, {prompt: true, ignore_date: true, minute_step: 15, class: "opening-hour"} %> 〜
<%= f.time_select :close_time, {prompt: true, ignore_date: true, minute_step: 15, class: "opening-hour"} %>
After reloading and checking with the verification tool ...
The class name was not given.
I referred to the following blog article. How to use date_select [Rails]
time_field reference, Helper options and HTML attributes are listed respectively. The two had to be separated rather than put in the same {}. By rewriting my code as follows, the class name was successfully assigned!
<%= f.time_select :open_time, {prompt: true, ignore_date: true, minute_step: 15}, {class: "opening-hour"} %> 〜
<%= f.time_select :close_time, {prompt: true, ignore_date: true, minute_step: 15}, {class: "opening-hour"} %>
Since the class name was given, after that, I was able to carry out the implementation I thought was safe by doing 2.3 in the order!
Recommended Posts