I have the following simple_form input (HAML):
= congress_detail_form.input :stand_setup_time, as: :time
The as: :time part may be redundant as the database column type is TIME, which I think simple_form detects.
It defaults to the current time (it shows two selects, one for the hour, the other for the minute). I have been unable to set a default of 00:00 using default: or value:. Is this even possible?
I've been unable to find where in the simple_form codebase this default is set. Any help would be appreciated.
I've also found no timepicker that works with simple_form.
Time value format The value of the time input is always in 24-hour format that includes leading zeros: hh:mm, regardless of the input format, which is likely to be selected based on the user's locale (or by the user agent). If the time includes seconds (see Using the step attribute), the format is always hh:mm:ss.
HTML <input type="time"> 1 Definition and Usage. The <input type="time"> defines a control for entering a time (no time zone). Tip: Always add the <label> tag for best accessibility practices! 2 Browser Support. The numbers in the table specify the first browser version that fully supports the element. 3 Syntax
Time value format. The JavaScript code adds code to the time input to watch for the input event, which is triggered every time the contents of an input element change. When this happens, the contents of the <span> are replaced with the new value of the input element.
If the time includes seconds (see Using the step attribute ), the format is always hh:mm:ss. You can learn more about the format of the time value used by this input type in Time strings in Date and time formats used in HTML.
i'm able to do this with default option:
= congress_detail_form.input :stand_setup_time, as: :time, default: Time.parse('8:00')
I would say you setting default values to the instance variable in the controller.
Assuming you render your view from CongressesController
:
class CongressesController < ApplicationController
...
def new
@congress_detail = CongressDetail.new(stand_setup_time: Time.parse('00:00'))
end
...
end
It allows you to have your views smaller and clearer. And that's how you should keep them =)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With