[JAVA] I want to give a class name to the select attribute

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.

What you want to do

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) f1d0dc39dd28504edcd3be06647cbad1.png 95f4366f509951f98ab68ff151686fa3.png

Stumble point

Class name is not given to select attribute! I was thinking of proceeding in the following order, but my nose was brilliantly crushed.

  1. Give the same class name to the corresponding select attribute
  2. Get all the elements with the target class name in Javascript
  3. Change the value of the field obtained by the forEach function to '00'

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 ... c0feeff4834008d06bcb50ce6cfb9a04.png

The class name was not given.


Helper options and html options need to be written separately.

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

I want to give a class name to the select attribute
I want to create a form to select the [Rails] category
I want to call a method of another class
I want to display the name of the poster of the comment
I want to add a delete function to the comment function
I want to recursively get the superclass and interface of a certain class
I want to call a method and count the number
I want to recursively search the class list under the package
I want to create a chat screen for the Swift chat app!
I want to change the value of Attribute in Selenium of Ruby
I want to develop a web application!
I want to write a nice build.gradle
I want to write a unit test!
I want to get the field name of the [Java] field. (Old tale tone)
I want you to use Enum # name () for the Key of SharedPreference
I want to output the day of the week
[Ruby] I want to do a method jump!
I want to var_dump the contents of the intent
I want to simply write a repeating string
I want to design a structured exception handling
I want to truncate after the decimal point
I want to get the value in Ruby
I want to play a GIF image on the Andorid app (Java, Kotlin)
I want to get a list of only unique character strings by excluding fixed character strings from the file name
[Java] I want to calculate the difference from the date
I want to embed any TraceId in the log
I tried to decorate the simple calendar a little
I want to use a little icon in Rails
I want to know the answer of the rock-paper-scissors app
I want to dark mode with the SWT app
I want to monitor a specific file with WatchService
I want to define a function in Rails Console
I want to call the main method using reflection
I want to add a reference type column later
I want to click a GoogleMap pin in RSpec
[Rough commentary] I want to marry the pluck method
I want to be aware of the contents of variables!
I want to return the scroll position of UITableView!
I want to simplify the log output on Android
I want to connect to Heroku MySQL from a client
I want to create a generic annotation for a type
Rspec: I want to test the post-execution state when I set a method on subject
[Ruby] I want to make a program that displays today's day of the week!
I want to go back to a specific VC by tapping the back button on the NavigationBar!
I want to use PowerMock in a class that combines parameterized tests and ordinary tests
[Rails] I want to display the link destination of link_to in a separate tab
I want to read the property file with a file name other than application.yml or application- [profile name] .yml with Spring Boot.
How to get the class name / method name running in Java
[Java] I want to convert a byte array to a hexadecimal number
I want to find a relative path in a situation using Path
I want to set the conditions to be displayed in collection_check_boxes
[Rails] [bootstrap] I want to change the font size responsively
I want to use screen sharing on the login screen on Ubuntu 18
(´-`) .. oO (I want to easily find the standard output "Hello".
I want to bring Tomcat to the server and start the application
I want to implement a product information editing function ~ part1 ~
How to create a form to select a date from the calendar
I want to expand the clickable part of the link_to method
I want to make a specific model of ActiveRecord ReadOnly
I want to change the log output settings of UtilLoggingJdbcLogger
I want to make a list with kotlin and java!