Perfect for standard case.
Set default value.
Label hours, minutes etc. as you wish. Useful for internationalization.
Hide original input from users.
Show widget when original input gets focus.
Let users decide how they want to input values.
The input can be a child or a sibling of its label. Label is not obligatory, but definitely a best practise.
cssClass
Type: string
Default: duration-initialized
Class added to original input after initialization.
display
Type: string
Default: both
Indicated widget display. Can take of of the following values:
both
- original input and the widget are displayed.popup
- widget is displayed as popup when original input is gets focus.switcher
- only one of original input and widget is displayed at the same time. Switcher allows to toggle between original input and widget.widget
- original input is hidden, only widget is displayed.initialValue
Type: object
Default:
initialValue: {
years: '0',
months: '0',
weeks: '0',
days: '0',
hours: '0',
minutes: '0',
seconds: '0'
}
Initial values for generated inputs.
inputs
Type: array
Default: ['years', 'months', 'weeks', 'days', 'hours', 'minutes', 'seconds']
List of inputs to be generated. If you set outputFormat
to decimal
, only hours and minutes inputs will be generated automatically (days, weeks, months and year are not valid in this context). Use inputs
option to decide if you want seconds displayed as well.
labels
Type: object
Default:
labels: {
years: 'yrs',
months: 'mo',
weeks: 'wks',
days: 'days',
hours: 'hrs',
minutes: 'min',
seconds: 'sec'
}
Default labels for generated inputs.
outputFormat
Type: string
Default: 'iso'
Can be set to iso
or decimal
.
precision
Type: integer
Default: 2
, if inputs
contains seconds
precision is set to 5
Precision used by the widget to format computation result. Be cautious with setting it too high to avoid problems with rounding errors.
screenReaderText
Type: string
Default: 'sr-only'
To avoid duplication for sighted users additional label can be hidden using specified class. Don't use display: none
- it breaks accessibility of the widget.
sizingElement
Type: string
Default: 'input'
Can be set to input
or wrapper
.
Used to size widget when display popup
is used. Widget will be positioned and sized correspond to selected element. If no wrapper was given as option default (generated) wrapper will be used.
switcher
Type: object
Default:
switcher: {
labelShows: 'alternative',
firstLabel: 'Switch to input widget',
secondLabel: 'Switch to preformatted value input',
initialState: 'first'
}
Values to configure switcher.
labelShows
can take one of two values: alternative
or current
. If current
is chosen, switcher in on state displays on label and off label in off state. If alternative
is chosen, switcher displays the other option's name.firstLabel
describes switchers on state.secondLabel
describes switchers off state.initialState
can be first
or second
and indicated in which state the swicher should be after initialization.wrapper
Type: selector or HTMLElement
Default: false
A wrapper containing original input and widget HTML. If set, given element will be used. If not set wrapping element (div
) will be created automatically.
destroy
Removes all custom HTML code and event listeners.
durationinitialized
Fired when all custom HTML code is ready and event listeners got initialized.
durationdestroyed
Fired after completing destroy action.
You will find all the code on Github.