v7.3.0

DurationField
Widget

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
No results

Configs

Configs are options you supply in a configuration object when creating an instance of this class
  • Set to true to 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 true the field will use short names of unit durations (as returned by getShortNameOfUnit) when creating the input field's display value.

  • 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.

    Has a corresponding runtime triggers property.

Properties

Properties are getters/setters or publicly accessible variables on this class
  • 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.

  • milliseconds : Number
    READONLY

    The milliseconds property is a read-only property which returns the number of milliseconds in this field's value

  • isDurationField : Booleantrue
    READONLY
    ADVANCED
    Identifies an object as an instance of DurationField class, or subclass thereof.

Events

Events are triggered for certain actions in this class and can be listened for to react to those actions in your code

Event handlers

Event handlers are callbacks called as a result of certain actions in this class
type: durationfield

Source path

Core/widget/DurationField.js

Contents