A time form function

Ninja Overlord - June 1, 2008 - 18:55
Project:Helpers
Version:5.x-1.x-dev
Component:Miscellaneous
Category:feature request
Priority:normal
Assigned:Ninja Overlord
Status:duplicate
Description

A form function to return time in a way to put into an options set for something would be good - have an hour field that could be 0-23 or 1-12 depending on another input for 12 or 24 hour, if it is 12 be sure to include am/pm select box at the end. Also good to have it be optional or which fields are returned (I can see reasons why some would want a seconds field, although I myself have no direct need for that).

#1

NancyDru - June 2, 2008 - 15:16
Status:active» postponed (maintainer needs more info)

Sounds useful. Do you have a patch and documentation?

#2

Ninja Overlord - June 2, 2008 - 19:01

The post was to see if it would be friendly, I'll start writing it now.

#3

NancyDru - June 2, 2008 - 19:11

Yes, it would be a good idea. First, see if the Date API module has this before spending much time on it.

I do ask that documentation (see the docs link from the project page) accompany the patch.

And when you submit a patch, assign the issue to yourself.

#4

Ninja Overlord - June 2, 2008 - 20:41
Status:postponed (maintainer needs more info)» needs review

Here's a patch - in looking at the other functions it seems the trend is to create an entire field to put in, but I felt uncomfortable doing that - what I wrote could be utilized to produce that easily enough though should that be the desired direction.

I havn't spent that much time on this, doing 5 things at once is the only reason why it took so long. I haven't yet looked at the date api either (saw your post after I produced the patch)

AttachmentSize
helpers_form.patch 1.87 KB

#5

Ninja Overlord - June 2, 2008 - 20:42
Assigned to:Anonymous» Ninja Overlord

Can't change assign when not creating a new post.

#6

Ninja Overlord - June 2, 2008 - 21:05

For the documentation page, should this patch be integrated:

time_select_for_form($hour = 12)
This will return the options selection for an '#options' for a selection. From this point, it is a relatively easy thing to construct a time selection.

  • Calling parameters
    $hour
    Pass this as anything other than a 12, and the function shall be formatted for a 24 hour timeframe, pass no argument, and it shall return for a 12 hour timeframe
  • Return
    An array with keys, the 'hour' key will have the hours options, 'minute' key will have the minutes options, the 'second' key will have the seconds options, and if it is a 12 hour format, the 'ampm' key will have the am and pm options.

#7

NancyDru - June 2, 2008 - 22:32

I think typically, we would actually produce a form element(s). I'll take a look.

Only 5 things? That's taking it easy! ;-)

#8

Ninja Overlord - June 3, 2008 - 06:38

Okay, updated it to fit with other parts of the module.

Documentation:

time_select_for_form($select, $hour = FALSE, $title = 'Time', $default_value = NULL, $required = FALSE, $description = '', $multiple = FALSE)

  • Calling parameters
    $select
    To choose which options to provide. The choices are 'hour', 'minute', 'second', 'ampm'.
    $hour
    If this value is TRUE, then it will be returning hour in a 12 hour format, if not passed, it will return hour in a 24 hour format.
    $title
    Defaults to "Time" and it will always be translated.
    $default_value
    The selected value when the page loads. Do not include leading 0's for values under 10. The select form will have them, but don't include them in the call.
    $required
    Whether the element should be required or not.
    $description
    optionally provide a description. it Is translated.
    $multiple
    Whether or not to allow multiple choices.
  • Return
    A compleated form element ready to be used.

As far as other developments I could forsee doing in time (came to me when writing this post)

Add a prefix and suffix to the select adding div's (being dependant on the $select) for CSS guru's - having an hour select, a minute select, a second select, and an ampm select is all well and good, but by default they would be one above the other. Better if they are side by side.

In addition to provide an 'NA' option if it is not required (NA would work in a select for 2 numbers/letters as these all are).

AttachmentSize
helpers_form2.patch 2.29 KB

#9

NancyDru - February 9, 2009 - 17:11

Thanks for this. I didn't particularly like it, but I did like the idea. #371604: Add a time form builder for forms

#10

NancyDru - February 9, 2009 - 17:11
Status:needs review» duplicate
 
 

Drupal is a registered trademark of Dries Buytaert.