12 hour time select with AM/PM select options

818 views
Skip to first unread message

Andrew

unread,
Jul 25, 2011, 6:57:00 PM7/25/11
to SimpleForm
Hello,

I would like to turn a regular 24 hour time select input into a 12
hour time select with an additional AM/PM select input. For example:

Before:

[00..23] : [00..59]

After:

[1..12] : [00..59] [AM,PM]

How can I achieve this sort of thing using simple_form? Has this been
done before? Is there a plugin or gem that I can install?

Thanks,
Andrew

Andrew

unread,
Jul 27, 2011, 11:51:46 AM7/27/11
to SimpleForm
An example of how to create a custom form element like this would also
be helpful.

Carlos Antonio

unread,
Jul 27, 2011, 12:01:07 PM7/27/11
to plataformate...@googlegroups.com
I believe this feature was added to Rails 3.x with time/datetime selects. I don't know the api off the top of my head, by I think it's just to give an :ampm => true option to the select helpers. So, it'd be basically the same with simple form, which will just delegate these arguments to Rails handle.

# Sth like that (untested)
f.input :my_time, :as => :time, :ampm => true

You should also be able to take a look at Rails docs do find related docs.

-- 
At.
Carlos A. da Silva

Andrew

unread,
Jul 27, 2011, 5:21:00 PM7/27/11
to SimpleForm
> I believe this feature was added to Rails 3.x with time/datetime selects.

Thanks for the response. Unfortunately, I have already tried this, and
the :ampm option doesn't work the way you think it would. It simply
adds "AM" or "PM" label to the hour option. So you get a form input
that looks like this:

[12 PM] : [30]

...which is totally not what I want. There are still 24 options in the
hour select. I want 12 hour options with an additional select input
with two options (AM and PM).

--Andrew
Reply all
Reply to author
Forward
0 new messages