Rails time field's value key not rendering

Viewed 53

According to the documentation for the time_field, you can define the format in the object's value, like "%T.%L" in order to allow input of milliseconds.

in my view I have:

.field
  = f.label :start
  = f.time_field :start, value: "%T.%L"

The input tag renders as: screen shot of input time field

I also tried it this way:

f.time_field :start, value: "%H:%M:%S.%L"

but that too rendered the same way.

Documentation is sparse though: https://apidock.com/rails/v4.0.2/ActionView/Helpers/FormHelper/time_field

1 Answers

This isn't part of the Rails form helpers documentation; rather, I found it as part of the HTML5 inputs itself:

HTML5 Time Element in Form with Milliseconds

So I modified my own code to be:

f.time_field :start, step: 0.001

And it renders this way: Screenshot of time input rendering with milliseconds

Only have to remove that PM part, but from what I can tell it's just a matter of CSS for that part.

Related