# jQuery UI Timepicker (By François Gélinas)

## What is this?

This is a jQuery UI time picker plugin build to match with other official jQuery UI widgets like the date picker.
Based on the existing date picker, this plugin will integrate nicely with your form and use your selected jQuery UI theme.
The plugin is very easy to integrate in your form for you time (hours / minutes) inputs.

## Usage:

    $('#timepicker').timepicker({
        // Options
        timeSeparator: ':',           // The character to use to separate hours and minutes. (default: ':')
        showLeadingZero: true,        // Define whether or not to show a leading zero for hours < 10. (default: true)
        showMinutesLeadingZero: true, // Define whether or not to show a leading zero for minutes < 10. (default: true)
        showPeriod: false,            // Define whether or not to show AM/PM with selected time. (default: false)
        showPeriodLabels: true,       // Define if the AM/PM labels on the left are displayed. (default: true)
        altField: '#alternate_input', // Define an alternate input to parse selected time to
        defaultTime: '12:34',         // Define a default time to use if displayed inline or input is empty
        zIndex: null,                 // Overwrite the default zIndex used by the time picker

        // trigger options
        showOn: 'focus',              // Define when the timepicker is shown.
                                      // 'focus': when the input gets focus, 'button' when the button trigger element is clicked,
                                      // 'both': when the input gets focus and when the button is clicked.
        button: null,                 // jQuery selector that acts as button trigger. ex: '#trigger_button'

        // Localization
        hourText: 'Hour',             // Define the locale text for "Hours"
        minuteText: 'Minute',         // Define the locale text for "Minute"
        amPmText: ['AM', 'PM'],       // Define the locale text for periods

        // Events
        onSelect: onSelectCallback,   // Define a callback function when an hour / minutes is selected.
        onClose: onCloseCallback,     // Define a callback function when the timepicker is closed.
        onHourShow: onHourShow,       // Define a callback to enable / disable certain hours. ex: function onHourShow(hour)
        onMinuteShow: onMinuteShow    // Define a callback to enable / disable certain minutes. ex: function onMinuteShow(hour, minute)
    });

## Examples :

Default time picker :
[Show code]

    $('#timepicker').timepicker();

Time picker with "h" time separator :
[Show code]

     $('#timepicker').timepicker({
            timeSeparator: 'h:'
        });

Time picker with period (AM/PM) in input and without hours leading 0s :
[Show code]

    $('#timepicker').timepicker({
        showPeriod: true,
        showLeadingZero: false
    });

Time picker with period (AM/PM) in input and with hours leading 0s :
[Show code]

    $('#timepicker').timepicker({
        showPeriod: true,
        showLeadingZero: true
    });

Time picker without period in text input and without hours leading 0s :
[Show code]

    $('#timepicker').timepicker({
        showPeriod: false,
        showLeadingZero: false
    });

Time picker with labels in another language (Français) :
[Show code]

    $('#timepicker').timepicker({
        hourText: 'Heures',
        minuteText: 'Minutes',
        amPmText: ['AM', 'PM'],
        timeSeparator: 'h'
    });

Time picker with disabled hours / minutes. 8:30 PM to 6:30 AM disabled :
[Show code]

    $('#timepicker').timepicker({
            showPeriod: true,
            onHourShow: OnHourShowCallback,
            onMinuteShow: OnMinuteShowCallback
        });
    function OnHourShowCallback(hour) {
        if ((hour > 22) || (hour < 6)) {
            return false; // not valid
        }
        return true; // valid
    }
    function OnMinuteShowCallback(hour, minute) {
        if ((hour == 22) && (minute >= 30)) { return false; } // not valid
        if ((hour == 6) && (minute < 30)) { return false; }   // not valid
        return true;  // valid
    }

Define when the time picker is shown with the `showOn` option and set a trigger element with the `button` option
[Show code]

    $('#timepicker').timepicker({
            showOn: 'button',
            button: '.timepicker_button_trigger'
    });

Time picker without the AM/PM labels on the left (showPeriodLabels option set to false:
[Show code]

    $('#timepicker').timepicker({
        showPeriodLabels: false,
    });

onSelect (hours and minutes both trigger event) and onClose events :
[Show code]

    function log_event(event) {
        $('#events_log').val(
            $('#events_log').val() + "\n" + event
        )
    }
    $('#timepicker').timepicker({
        onClose: function(time, inst) {
            log_event('onClose triggered with time : ' + time + ' for instance id : ' + inst.id);
        },
        onSelect: function(time, inst) {
            log_event('onSelect triggered with time : ' + time + ' for instance id : ' + inst.id);
        }
    });

events log :

Inline time picker : Alternate field :
[Show code]

    $('#timepicker_inline_div').timepicker({
       altField: '#timepicker_alt_input',
       defaultTime: '9:20'
    });
    function setNewTime() {
        $('#timepicker_inline_div').timepicker('setTime','14:55');
    }

## Requirements :

- jQuery 1.5.1 (probably works with previous versions)
- jQuery UI Core (included in jquery-ui-x.x.x.custom.min.js)
- jQuery UI Theme.css (included in jquery-ui-x.x.x.custom.css)
- jquery.ui.timepicker.js
- jquery-ui-timepicker.css

New! New! TimePicker is not 100% more social, on GitHub @ http://github.com/fgelinas/timepicker.

Get the release package here : jquery-ui-timepicker-0.2.zip

## Releases :

0.2 - May 28, 2011
  In the last release, I messed up versions and lost some changes so I'm fixing all this up with release 0.2
0.1.2 - May 26, 2011
  Fixed a bug with inline timepickers that would append a #timepickr hashtag when selecting hours and minutes.
  Fixed z-index problem with IE6 (Thanks Graham Bentley)
  Added selection of highlighted text when enter is pressed on the input field (Thanks Glen Chiacchieri)
  Adjusted some focus problems, now the input gets the focus back when the used click on hours / minutes.
0.1.something aka the lost release - around April 11
  Fixed a bug for when input Id had a dot in it, it was getting double escaped when it should not. (Thanks Zdenek Machac)
  So in 0.1.1 I created a bug that made timepicker changes the location hash, well now it's fixed. (Thanks Lucas Falk)
0.1.1 - April 6, 2011
  Changed the cells click and dblclick binding for faster rendering in IE6/7 (Thanks Blair Parsons)
  Fixed a class naming bug created in 0.1.0 (Thanks Morlion Peter)
0.1.0 - March 23, 2011
  Fixed some bugs with version 0.0.9
0.0.9 - March 22, 2011
  Added zIndex option (Thanks Frank Enderle)
  Added showPeriodLabels option (default: true) to show/hide AM/PM labels on the left (thanks Frank Enderle)
  Added showOn ['focus'|'button'|'both'] and button options for alternate trigger method
0.0.8 - February 17, 2011
  Fixed close event not triggered when switching to another input with time picker (thanks Stuart Gregg)
0.0.7 - February 10, 2011
  Added function to set time after initialisation :$('#timepicker').timepicker('setTime',newTime);
  Added support for disabled period of time : onHourShow and onMinuteShow (thanks Rene Felgenträger)
0.0.6 - January 19, 2011
  Replaced some div with tables to : fix some display bugs in IE7, fix inline display and fix my headhake.
  Added standard "change" event being triggered on the input when the content changes. (Thanks Rasmus Schultz)
  Added support for inline timePicker, attached to div or span.
  Added altField that receive the parsed time value when selected time changes.
  Added defaultTime value to use when input field is missing (inline) or input value is empty. If defaultTime is missing then current time is used.
0.0.5 - January 18, 2011
  Now updating time picker selected value when manually typing in the text field (thanks Rasmus Schultz)
  Another step toward inline time picker ?
  Fixed : with showPeriod: true and showLeadingZero: true, PM hours did not show leading zeros (thanks Chandler May)
  Fixed : with showPeriod: true and showLeadingZero: true, Selecting 12 AM shows as 00 AM in the input field, also parsing 12AM did not work correctly (thanks Rasmus Schultz)
0.0.4 - January 10, 2011
  Changed showLeadingZero to affect only hours, added showMinutesLeadingZero for minutes display.
  Changed the default value of timeSeparator from 'h' to ':'.
  Removed width:100% on tables in the css, caused a bug in some browsers.
0.0.3 - January 8, 2011
  Fixed a bug with the widget not displaying with some jQuery UI 1.8.7 css. (Thanks Alexander Fietz)
  Fixed a display bug on page load, a small empty div was visible at the bottom of pages. (Thanks Gertjan van Roekel)
  Modified the jquery-ui-timepicker.css to make the widget more dynamic to style and sizes changes.
0.0.2 - January 4, 2011
  Added showPeriod: period (AM/PM) in input and showLeadingZero: to control display of number < 10. (big thanks Steve Commisso)
0.0.1 - December 2010
  First release

## To Do :

- Change the code style to use the jQuery widget framework.
- Detect a second click on the same cell and close the picker (ie: the user selected hours and do not want to select different minutes or vice versa, and click twice on the same cell instead) This is already simulated with the handling of the double click.

Bug, ideas or comments : frank@fgelinas.com
--
Francois Gelinas