Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set default time for simple_form time input

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.

like image 778
danebez Avatar asked Oct 31 '13 09:10

danebez


People also ask

What is the default format for time input?

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.

How to use input type of time in HTML?

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

What is the use of timetime in JavaScript?

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.

What is the format of the time value used by step?

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.


2 Answers

i'm able to do this with default option:

= congress_detail_form.input :stand_setup_time, as: :time, default: Time.parse('8:00')
like image 143
sprimon Avatar answered Oct 27 '22 12:10

sprimon


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 =)

like image 25
Ngoral Avatar answered Oct 27 '22 14:10

Ngoral