new InputDuration()
Class for the Input-Duration webcomponent
Boolean attributes `show-days`, `no-hours`, `no-minutes`, `no-seconds`, and
`no-microseconds` control field visibility. String attributes
`hours-divider`, `minutes-divider`, `seconds-divider`, and
`microseconds-divider` customize the separators; `days-divider` customizes
the day label. Divider values are rendered as text.
The days field grows to fit larger counts and has extra spacing before its
divider to emphasize the less-common unit.
User edits update the public value and form state when the field changes,
after its intermediate input has been normalized.
The element is form-associated in supporting browsers; use `name`,
`required`, and `disabled` attributes for form submission and validation.
Example
<input-duration no-microseconds hours-divider="h " microseconds-divider="ms"></input-duration>
Extends
- HTMLElement
Members
dayFriendlyValue
Gets a normalized, unit-labeled duration.
disabled
Whether the control is disabled.
disabled
Sets whether the control is disabled.
myElement :ShadowRoot
Shadow root containing this component's controls.
Type:
- ShadowRoot
validationMessage
Validation message for the current form state.
validity
Current form validity state.
value
Gets the last committed duration value.
value
Sets the duration using `HH:mm:ss.SSS` or `D:HH:mm:ss.SSS` format.
willValidate
Whether this control participates in constraint validation.
(static) observedAttributes
HTML attributes that update the component when changed.
Methods
add0s()
eventlistener that adds 0s to preface numbers less than 10 triggered by
the change event of the input
addArrowKeyInput()
Handles arrow-key adjustment and field navigation while keeping the
active field selected.
addClicksToActivate()
eventlistener that adds click to activate input of values by the keyboard triggered by
the click event of the input
addFormValueSync() → {void}
Commits edits after a field change, once its value has been normalized.
Returns:
- Type
- void
addHTML()
updates inputs-duration marked with shadow html and css
addNumberLooping()
eventlistener that adds number looping for up and down keys triggered by
the change event of the input
addNumericInput()
Filters numeric input and advances to the next unit. If the next unit is
hidden, focus leaves the control once the current field is complete.
attributeChangedCallback(name, oldValuenullable, newValuenullable) → {void}
Updates the rendered control when an observed attribute changes.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
name |
string | Changed attribute name. | |
oldValue |
string |
<nullable> |
Previous attribute value. |
newValue |
string |
<nullable> |
New attribute value, or null when removed. |
Returns:
- Type
- void
boot()
Called from constructor, sets up the html and event listeners
checkValidity() → {boolean}
Runs constraint validation and fires an invalid event when needed.
Returns:
Whether the control is valid.
- Type
- boolean
disable()
Disables the entire control and excludes it from form submission.
enable() → {void}
Enables the duration fields.
Returns:
- Type
- void
formDisabledCallback(disabled) → {void}
Disables or enables the internal fields when the form disables this control.
Parameters:
| Name | Type | Description |
|---|---|---|
disabled |
boolean | Whether the control is disabled. |
Returns:
- Type
- void
formResetCallback() → {void}
Restores the initial value when its form is reset.
Returns:
- Type
- void
formStateRestoreCallback(state, mode) → {void}
Restores the duration and required state saved by the browser.
Parameters:
| Name | Type | Description |
|---|---|---|
state |
string | Serialized duration state. |
mode |
string | Browser restoration mode. |
Returns:
- Type
- void
hideDays() → {void}
Hides the days field and its adjacent divider.
Removes the `show-days` attribute.
Returns:
- Type
- void
hideHours() → {void}
Hides the hours field and its adjacent divider.
Sets the `no-hours` attribute.
Returns:
- Type
- void
hideMicroSeconds() → {void}
Hides the milliseconds field and its adjacent divider or suffix.
Sets the `no-microseconds` attribute.
Returns:
- Type
- void
hideMinutes() → {void}
Hides the minutes field and its adjacent divider.
Sets the `no-minutes` attribute.
Returns:
- Type
- void
hideSeconds() → {void}
Hides the seconds field and its adjacent divider.
Sets the `no-seconds` attribute.
Returns:
- Type
- void
isValidValue(val) → {boolean}
Checks whether a value follows the supported duration format and ranges.
Parameters:
| Name | Type | Description |
|---|---|---|
val |
* | Candidate value. |
Returns:
Whether the value follows a supported duration format.
- Type
- boolean
noHours() → {void}
Backward-compatible alias for InputDuration#hideHours.
Returns:
- Type
- void
noMicroSeconds() → {void}
Backward-compatible alias for InputDuration#hideMicroSeconds.
Returns:
- Type
- void
noMinutes() → {void}
Backward-compatible alias for InputDuration#hideMinutes.
Returns:
- Type
- void
noSeconds() → {void}
Backward-compatible alias for InputDuration#hideSeconds.
Returns:
- Type
- void
nonNumericBugInHTML()
eventlistener that adds key filtering to stop letters (or other non-numerics) from being input triggered by
the keypress event of the input
removeEprop()
Stop event propigation from the timeCase up through the DOM so when keys
are being used they don't affect other controls (like volume on plyr)
reportValidity() → {boolean}
Runs constraint validation and asks the browser to report any error.
Returns:
Whether the control is valid.
- Type
- boolean
resetInputs() → {void}
Resets all duration fields to zero.
Returns:
- Type
- void
setDaysDivider(text) → {void}
Replaces the day/hour separator.
Also available through the `days-divider` attribute.
Parameters:
| Name | Type | Description |
|---|---|---|
text |
string | Divider text to display. |
Returns:
- Type
- void
setHoursDivider(text) → {void}
Replaces the hours/minutes separator.
Also available through the `hours-divider` attribute.
Parameters:
| Name | Type | Description |
|---|---|---|
text |
string | Divider text to display. |
Returns:
- Type
- void
setInputValues(val) → {void}
Copies a validated duration string into the shadow inputs.
Parameters:
| Name | Type | Description |
|---|---|---|
val |
string | Valid duration in `HH:mm:ss.SSS` format. |
Returns:
- Type
- void
setMicroSecondsDivider(text) → {void}
Sets a suffix to display after milliseconds.
Also available through the `microseconds-divider` attribute.
Parameters:
| Name | Type | Description |
|---|---|---|
text |
string | Suffix text to display. |
Returns:
- Type
- void
setMinutesDivider(text) → {void}
Replaces the minutes/seconds separator.
Also available through the `minutes-divider` attribute.
Parameters:
| Name | Type | Description |
|---|---|---|
text |
string | Divider text to display. |
Returns:
- Type
- void
setSecondsDivider(text) → {void}
Replaces the seconds/milliseconds separator.
Also available through the `seconds-divider` attribute.
Parameters:
| Name | Type | Description |
|---|---|---|
text |
string | Divider text to display. |
Returns:
- Type
- void
showDays() → {void}
Shows the days field and its adjacent divider.
Sets the `show-days` attribute.
Returns:
- Type
- void
showHours() → {void}
Shows the hours field and its adjacent divider.
Removes the `no-hours` attribute.
Returns:
- Type
- void
showMicroSeconds() → {void}
Shows the milliseconds field and its adjacent divider or suffix.
Removes the `no-microseconds` attribute.
Returns:
- Type
- void
showMinutes() → {void}
Shows the minutes field and its adjacent divider.
Removes the `no-minutes` attribute.
Returns:
- Type
- void
showSeconds() → {void}
Shows the seconds field and its adjacent divider.
Removes the `no-seconds` attribute.
Returns:
- Type
- void
updateDividers() → {void}
Synchronizes divider text and shows one separator between each pair of
visible units, including when intervening units are hidden.
Returns:
- Type
- void
updateFormValue() → {void}
Keeps the form-associated value synchronized with the displayed duration.
Returns:
- Type
- void
updateVisibleFields() → {void}
Synchronizes field and divider visibility with the `no-*` attributes.
The days field grows for longer values; its minimum matches other fields.
Returns:
- Type
- void
warnInvalidValue(val) → {void}
Reports a value that does not match the supported duration format.
Parameters:
| Name | Type | Description |
|---|---|---|
val |
* | Rejected value. |
Returns:
- Type
- void