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.
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
Properties
Properties are getters/setters or publicly accessible variables on this class-
Identifies an object as an instance of DurationField class, or subclass thereof.
-
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 -
Identifies an object as an instance of DurationField class, or subclass thereof.