DurationField
A text field for editing Duration values, allowing the user to enter both a numeric magnitude and a time unit (e.g. '2d', '4 hours'). The field parses user input into a Duration object and displays the value using configurable unit abbreviations. Use spin triggers to increment/decrement the value by the configured step. Restrict allowed units with allowedUnits and enforce bounds with min and max. This field can be used as a cell editor in a Grid and is the default editor for DurationColumn.
new DurationField({ appendTo : targetElement, width : 200, label : 'Duration', value : '15 min', step : '5 min', rendition : 'outlined' }); new DurationField({ appendTo : targetElement, width : 200, label : 'Duration', value : '10 d', step : '1 d', rendition : 'filled' }); const durationField = new DurationField({
label : 'Task duration',
value : '3 days',
min : '1d',
max : '30d',
appendTo : document.body
});
Useful configs and properties
| Config | Description |
|---|---|
| value | Duration value as string, number, object, or Duration |
| unit | Default duration unit ('day', 'hour', etc.) |
| min | Minimum allowed duration (e.g. '1d') |
| max | Maximum allowed duration (e.g. '10d') |
| step | Step size for spin button clicks |
| allowedUnits | Comma-separated list of permitted units |
| useAbbreviation | Use short unit names (e.g. 'd' instead of 'day') |
| allowNegative | Allow negative duration values |
See also
- Duration - The Duration value object returned by this field
- TextField - Base text field class
- DateHelper - Utility for parsing duration strings and unit names
Configs
Configs are options you supply in a configuration object when creating an instance of this class-
Set to
trueto allow negative duration -
Comma-separated list of units to allow in this field, e.g. "day,hour,year". Leave blank to allow all valid units (the default)
Has a corresponding runtime allowedUnits property.
-
The number of decimal places to allow. Defaults to no constraint.
-
The duration magnitude to use with the current unit value. Can be either an integer or a float value. Both "," and "." are valid decimal separators.
Has a corresponding runtime magnitude property.
-
Max duration value (e.g. 10d)
Has a corresponding runtime max property.
-
Minimum duration value (e.g. 1d)
Has a corresponding runtime min property.
-
When set to
truethe field will use short names of unit durations (as returned by getShortNameOfUnit) when creating the input field's display value. -
triggers : Object<String, FieldTriggerConfig>
Widgets that trigger functionality upon click. Each trigger icon is a Widget instance which may be hidden, shown and observed and styled just like any other widget.
- spin : FieldTriggerConfig
Shows up and down arrows to increase or decrease the field value based on the step
- clear : FieldTriggerConfig
Clears the field value, only available if this field is clearable
Has a corresponding runtime triggers property.
- spin : FieldTriggerConfig
-
Custom style spec to add to element
Has a corresponding runtime style property.
-
The default configuration for the container.
-
Object to apply to elements dataset (each key will be used as a data-attribute on the element)
Has a corresponding runtime dataset property.
-
A createElement config object or HTML string from which to create the Widget's element.
Has a corresponding runtime element property.
-
Widget id, if not specified one will be generated. Also used for lookups through Widget.getById
Has a corresponding runtime id property.
-
Element (or element id) to insert this widget before. If provided, appendTo config is ignored.
Has a corresponding runtime insertBefore property.
-
Element (or element id) to append this widget element to, as a first child. If provided, appendTo config is ignored.
Has a corresponding runtime insertFirst property.
-
A title to display for the widget. Only in effect when inside a container that uses it (such as TabPanel)
-
Internal listeners, that cannot be removed by the user.
-
Specify
trueto auto select field contents on focus -
Specify
trueto highlight field after external value changes -
The max number of characters for the input field
-
The min number of characters for the input field
-
Text to display in empty field.
Has a corresponding runtime placeholder property.
-
Configure as
trueto indicate that anullfield value is to be marked as invalid. This will optionally append a * to the field label if showRequiredIndicator is set.Has a corresponding runtime required property.
-
trueto automatically display a * after the label for this field when it is required.Has a corresponding runtime showRequiredIndicator property.
-
Set to
true, completely bypasses validation logic (could be userful if your field is noteditableto the user). -
Only valid if this Widget is floating. Set to
trueto centre the Widget in browser viewport space. -
Only valid if this Widget is floating or positioned. Element, Widget or Rectangle to which this Widget is constrained.
-
Set to
trueto move the widget out of the document flow and position it absolutely in browser viewport space. -
Defines what to do if document is scrolled while Widget is visible (only relevant when floating is set to
true). Valid values: ´null´: do nothing, ´hide´: hide the widget or ´realign´: realign to the target if possible. -
The Formula provider prefix currently being used
-
A list of property names to be set in the underlying input element from properties by the same name in this Field object if the value is not
== null. -
Sets the native
autocompleteproperty of the underlying input element. For more information, please refer to MDN -
Text alignment for the input field.
-
Sets custom attributes of the underlying input element. For more information, please refer to MDN
-
If you need to use something else than a default
inputelement, as the input element, provide the tag name here. Please note that this is used for advanced usage only, for example when using WebComponents (custom elements), and that the configured element must fulfil the same contract as a regular input element. -
Sets the
typeattribute of the underlying input element (password, hidden, date, color, etc.). -
The width to apply to the
.b-field-innerelement, which encompasses theinputelement and any triggers. If a number is specified,pxwill be used. -
Sets the native
spellcheckproperty of the underlying input element. For more information, please refer to MDN -
Set to
falseto not highlight a field as invalid while typing, to instead show it on ENTER key press or similar. -
Label, prepended to field
Has a corresponding runtime label property.
-
CSS class name or class names to add to any configured label
-
The width to apply to the
<label>element. If a number is specified,pxwill be used. -
The labels to add either before or after the input field. Each label may have the following properties:
htmlThe label text.align'start'or'end'which end of the field the label should go.
- html : String
Label text
- align : 'start'/'end'
Which end of the file the label should go
-
When this widget is a child of a Container, it will by default be participating in a flexbox layout. This config allows you to set this widget's align-self style.
Has a corresponding runtime alignSelf property.
-
When this widget is a child of a Container, it will by default be participating in a flexbox layout. This config allows you to set this widget's flex style. This may be configured as a single number or a
<flex-grow> <flex-shrink> <flex-basis>format string. numeric-only values are interpreted as theflex-growvalue.Has a corresponding runtime flex property.
-
Widget's height, used to set element
style.height. Either specify a valid height string or a number, which will get 'px' appended. We recommend using CSS as the primary way to control height, but in some cases this config is convenient.Has a corresponding runtime height property.
-
Widget's margin. This may be configured as a single number or a
TRBLformat string. numeric-only values are interpreted as pixels.Has a corresponding runtime margin property.
-
A widgets weight determines its position among siblings when added to a Container. Higher weights go further down.
-
Widget's width, used to set element
style.width. Either specify a valid width string or a number, which will get 'px' appended. We recommend using CSS as the primary way to control width, but in some cases this config is convenient.Has a corresponding runtime width property.
-
Initial text to show in badge.
Has a corresponding runtime badge property.
-
Event that should be considered the default action of the widget. When that event is triggered the widget is also expected to trigger an
actionevent. Purpose is to allow reacting to most widgets in a coherent way. -
The name of the property to set when a single value is to be applied to this Widget. Such as when used in a grid WidgetColumn, this is the property to which the column's
fieldis applied. -
Set to
falseto disable localization of this object. -
Set to
trueto apply the default mask to the widget. Alternatively, this can be the mask message or a Mask config object. -
Prevent tooltip from being displayed on touch devices. Useful for example for buttons that display a menu on click etc, since the tooltip would be displayed at the same time.
-
If you are rendering this widget to a shadow root inside a web component, set this config to the shadowRoot. If not inside a web component, set it to
document.body -
Set to
falseto not show the tooltip when this widget is disabled -
The class to instantiate to use as the scrollable. Defaults to Scroller.
-
The
bottomCSS absolute position for this widget. If specified, the widget is implicitly configured as positionable. -
Programmatic control over which column to start in when used in a grid layout.
Has a corresponding runtime column property.
-
The
inset-inline-startCSS absolute position for this widget. If specified, the widget is implicitly configured as positionable. -
Set this config to
falseto disable batching DOM updates on animation frames for this widget. This has the effect of synchronously updating the DOM when configs affecting the rendered DOM are modified. Depending on the situation, this could simplify code while increasing time spent updating the DOM. -
The
inset-inline-endCSS absolute position for this widget. If specified, the widget is implicitly configured as positionable. -
Programmatic control over how many columns to span when used in a grid layout.
Has a corresponding runtime span property.
-
The
topCSS absolute position for this widget. If specified, the widget is implicitly configured as positionable.
Properties
Properties are getters/setters or publicly accessible variables on this class-
Identifies an object as an instance of Badge class, or subclass thereof.
-
Identifies an object as an instance of Delayable class, or subclass thereof.
-
Identifies an object as an instance of DurationField class, or subclass thereof.
-
Identifies an object as an instance of Events class, or subclass thereof.
-
Identifies an object as an instance of FormulaField class, or subclass thereof.
-
Identifies an object as an instance of KeyMap class, or subclass thereof.
-
Identifies an object as an instance of Labelable class, or subclass thereof.
-
Identifies an object as an instance of Localizable class, or subclass thereof.
-
Identifies an object as an instance of RTL class, or subclass thereof.
-
Identifies an object as an instance of Validatable class, or subclass thereof.
-
A class property getter for the default values of internal properties for this class.
-
Returns an array containing all existing Widgets. The returned array is generated by this call and is not an internal structure.
-
This property yields
trueif the currently focused element has been reached through other means than mouse click. If theactiveElementmatches:focus-visible. -
Get/set the recomposeAsync config for all widgets. Setting this value will set the config for all existing widgets and will be the default value for newly created widgets. Set this value to
nullto disable the default setting for new widgets while leaving existing widgets unaffected.Has a corresponding recomposeAsync config.
-
Get/set the allowed units, e.g. "day,hour,year".
Has a corresponding allowedUnits config.
-
The duration magnitude to use with the current unit value. Can be either an integer or a float value. Both "," and "." are valid decimal separators.
Has a corresponding magnitude config.
-
Get/set the max value
Has a corresponding max config.
-
Get/set the min value (e.g. 1d)
Has a corresponding min config.
-
The
millisecondsproperty is a read-only property which returns the number of milliseconds in this field's value -
An empty array that can be used as a default value.
-
An empty object that can be used as a default value.
-
Identifies an object as an instance of DurationField class, or subclass thereof.
-
Identifies an object as an instance of Field class, or subclass thereof.
-
Identifies an object as an instance of TextField class, or subclass thereof.
-
Identifies an object as an instance of Widget class, or subclass thereof.
-
Set HTML content safely, without disturbing sibling elements which may have been added to the contentElement by plugins and features. When specifying html, this widget's element will also have the htmlCls added to its classList, to allow targeted styling.
-
Get widgets elements dataset or assign to it
Has a corresponding dataset config.
-
Get this widget's encapsulating HTMLElement, which is created along with the widget but added to DOM at render time.
Has a corresponding element config.
-
Get this widget's primary focus holding element if this widget is itself focusable, or contains focusable widgets.
-
Returns an object describing the focus and keyboard navigation aspects of this widget's focusElement.
-
Returns this widget's focusElement if that element can currently be given focus (e.g., this widget is not disabled, or hidden).
-
This property is set to
trueafter processing the initial paint for the widget. It remainsfalseduring the initial paint. The intended use for this flag is to avoid processing that will be handled by the first paint (similar to not firing events during the widget's initial configuration). If this field istrue, the initial paint has already taken place, otherwise, it has yet to run. This field differs fromisPaintedwhich checks that the widget's element is attached to the DOM. -
Get/set widgets id
Has a corresponding id config.
-
Element (or element id) to insert this widget before. If provided, appendTo config is ignored.
Has a corresponding insertBefore config.
-
Element (or element id) to append this widget element to, as a first child. If provided, appendTo config is ignored.
Has a corresponding insertFirst config.
-
The child element which scrolls if any. This means the element used by the scrollable.
-
Returns the
DomClassListfor this widget's class. This object should not be mutated. -
Get/set widgets elements style. The setter accepts a cssText string or a style config object, the getter always returns a CSSStyleDeclaration
Has a corresponding style config.
-
The input element at the heart if this field
-
Returns true if the field's input is empty
-
Returns true if the field value is valid
-
Text to display in empty field.
Has a corresponding placeholder config.
-
Configure as
trueto indicate that anullfield value is to be marked as invalid. This will optionally append a * to the field label if showRequiredIndicator is set.Has a corresponding required config.
-
trueto automatically display a * after the label for this field when it is required.Has a corresponding showRequiredIndicator config.
-
Returns the DOM
ValidityStatefor this widget's input element, ornullif there isn't one. -
The formula typed between the parentheses in a
=XXX(...)expression in the field's value if theXXXmatches an available FormulaProvider. -
Override to attach the keyMap keydown event listener to something else than this.element
-
Override to make keyMap resolve subcomponent actions to something else than this.features.
-
Get/set this widget's
align-selfflexbox setting. This may be set to modify how this widget is aligned within the cross axis of a flexbox layout container.Has a corresponding alignSelf config.
-
Get element's
offsetHeightor sets itsstyle.height, or specified height if element no created yet.Has a corresponding height config.
-
Get element's margin property. This may be configured as a single number or a
TRBLformat string. numeric-only values are interpreted as pixels.Has a corresponding margin config.
-
Accessor to the Scroller which can be used to both set and read scroll information.
-
Get elements
offsetWidthor sets itsstyle.width, or specified width if element not created yet.Has a corresponding width config.
-
Returns a copy of the full configuration which was used to configure this object.
-
This property is set to
truebefore theconstructorreturns. -
This property is set to
trueon entry to the destroy method. It remains on the objects after returning fromdestroy(). If isDestroyed istrue, this property will also betrue, so there is no need to test for both (for example,comp.isDestroying || comp.isDestroyed). -
Get id assigned by user (not generated id)
-
Get/sets and display badge, set to null or empty string to hide.
Has a corresponding badge config.
-
Get/set element's disabled state. Set to
'inert'to also set theinertDOM attribute.Has a corresponding disabled config.
-
A singleton error tooltip which activates on hover of invalid fields. before show, it gets a reference to the field and interrogates its active error list to display as the tip content.
-
true if no id was set, will use generated id instead (widget1, ...). Toggle automatically on creation
-
Get/set fields label. Please note that the Field needs to have a label specified from start for this to work, otherwise no element is created.
Has a corresponding label config.
-
Get the global LocaleHelper
-
Get the global LocaleManager
-
Determines visibility by checking if the Widget is hidden, or any ancestor is hidden and that it has an element which is visible in the DOM
-
Programmatic control over which column to start in when used in a grid layout.
Has a corresponding column config.
-
Returns
trueif this class usescompose()to render itself. -
This widget's twin that is placed in an overflow menu when this widget has been hidden by its owner, typically a Toolbar due to overflow. The
overflowTwinis created lazily by ensureOverflowTwin. -
Programmatic control over how many columns to span when used in a grid layout.
Has a corresponding span config.
-
Get this Widget's next sibling in the parent Container, or, if not in a Container, the next sibling widget in the same parentElement.
-
Get this Widget's parent when used as a child in a Container,
-
Get this Widget's previous sibling in the parent Container, or, if not in a Container, the previous sibling widget in the same parentElement.
Functions
Functions are methods available for calling on the class-
This optional class method is called when a class is mixed in using the mixin() method.
-
Clear caches, forces all calls to fromCache to requery dom. Called on render/rerender.
-
Internal function used to hook destroy() calls when using thisObj
-
Internal function used restore hooked destroy() calls when using thisObj
-
Auto detaches listeners registered from start, if set as detachable
-
Internal function used to run a callback function after an event is triggered
-
Removes all listeners registered to this object by the application.
-
Clears the value of this Field, and triggers the clear event.
-
Trigger event when fields input changes
Triggers: change
-
Called when disabled state is changed. Used to add or remove 'b-invalid' class for the invalid field based on current disabled state.
-
Template function which may be implemented by subclasses to synchronize input state and validity state upon completion of the edit.
-
Only valid for floating Widgets. Moves to the front of the visual stacking order.
-
Called on keyMapElement keyDown
-
Called by the Base constructor after all configs have been applied.
-
This method is called following an update to the widget's rendered DOM.
-
Disable the widget
-
Enable the widget
-
Unmask the widget
Events
Events are triggered for certain actions in this class and can be listened for to react to those actions in your code-
This event is fired after a widget's elements have been synchronized due to a direct or indirect call to recompose, if this results in some change to the widget's rendered DOM elements.
Event handlers
Event handlers are callbacks called as a result of certain actions in this class-
This event is called after a widget's elements have been synchronized due to a direct or indirect call to recompose, if this results in some change to the widget's rendered DOM elements.