Field

Base class for TextField and NumberField. Not to be used directly.

Most subclasses can be used as editors for the Column. The most popular are:

Configs

107

Common

listenersEvents

Container

The configuration for additional items associated to this field. This is typically used to add contextual fields related to a checkbox or radio button. See these classes for examples of nested fields.

This config can be provided as an array of widget config objects, an object with named widgets (see namedItems, or a config object for the whole field container.

To determine if the object is a namedItems object or a field container config, the object is checked for either a type or an items property. If it has either of these properties, it is a field container config object. Configuring the container is useful for applying classes or styles to the container as a whole.

For example, to add named items:

 new Checkbox({
     text : 'Separate shipping address',
     container : {
         address1 : {
             type : 'textfield'
         },
         address2 : {
             type : 'textfield'
         }
     }
 });

To style the container as well, move the items to the items property and add cls:

 new Checkbox({
     text : 'Separate shipping address',
     container : {
         cls   : 'address-form',
         items : {
             address1 : {
                 type : 'textfield'
             },
             address2 : {
                 type : 'textfield'
             }
         }
     }
 });
containValues: Boolean | String | function

The config controls how the value of nested items are handled when a parent container gets or sets its values.

The valid values for this config are:

  • null (the default) will include the values of this field's items if this field stores its own value.
  • true to always include the values of this field's items.
  • false to never include the values of this field's items.
  • 'nested' to include the values of this field's items as a nested object under the field's name. This field's value is stored as the 'value' property of that object.
  • Any other string is treated as the name of a property on this field. When truthy, the values of this field's items will be included.
  • A function can be supplied that must return a value given this field as its sole argument. If that value is truthy, this field's items will be included.
ParameterTypeDescription
fieldField

Field instance

Returns: Boolean
inline: Boolean

Set this config to true to always display items horizontally along with this field. This assigns an hbox as the layout to the container.

Alternatively, set this config to false to wrap this field's items below. This assigns a VBox as the layout to the container.

This config defaults to true if there is exactly one item, and false otherwise.

Input element

autoComplete: String= off

Sets the native autocomplete property of the underlying input element. For more information, please refer to MDN

inputAlign: String

Text alignment for the input field.

inputAttributes: Object<String, String>

Sets custom attributes of the underlying input element. For more information, please refer to MDN

inputTag: String

If you need to use something else than a default input element, 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.

inputType: String

Sets the type attribute of the underlying input element (password, hidden, date, color, etc.).

inputWidth: String | Number

The width to apply to the .b-field-inner element, which encompasses the input element and any triggers. If a number is specified, px will be used.

spellCheck: Boolean

Sets the native spellcheck property of the underlying input element. For more information, please refer to MDN

tabIndex: Number

The tab index of the input field or fields, or null for natural tab order (recommended). Setting to 0 is equivalent to natural tab order, but is unnecessary for fields since they are naturally tabbable (i.e., accessible via the TAB key). Setting to -1 disables tabbability but allows for focus to be set to the element programmatically.

From MDN documentation:

Warning: You are recommended to only use 0 and -1 as tabindex values. Avoid using tabindex values greater than 0 and CSS properties that can change the order of focusable HTML elements (Ordering flex items). Doing so makes it difficult for people who rely on using keyboard for navigation or assistive technology to navigate and operate page content. Instead, write the document with the elements in a logical sequence.

Set to false to not highlight a field as invalid while typing, to instead show it on ENTER key press or similar.

Label

hint: String | function

An optional string to display inside the input field as an overlay. This can be useful for displaying a field's units.

This config is ignored if hintHtml is set.

For example:

 {
     type  : 'numberfield',
     label : 'Temperature',
     hint  : '°C'
 }

This config can be set to a function to dynamically generate the hint text:

 {
     type  : 'numberfield',
     label : 'Duration',
     hint  : ({ value }) => (value === 1) ? 'Day' : 'Days'
 }

The function is passed an object with the following properties:

  • source A reference to the field instance.
  • value The current value of the field.

A hint function will be called when the field changes value.

ParameterTypeDescription
dataObject

A data object

data.sourceField

A reference to the field instance

data.value*

The current value of the field

Returns: String
hintHtml: String | function

This config is similar to hint except that this config is used to display HTML content. Since this can allow malicious content to be executed, be sure not to include user-entered data or to encode such data (see encodeHtml).

If this config is set, hint is ignored.

For example:

 {
     type     : 'numberfield',
     label    : 'Temperature',
     hintHtml : '<i>°C</i>'
 }

This config can be set to a function to dynamically generate the hintHtml text:

 {
     type     : 'numberfield',
     label    : 'Duration',
     hintHtml : ({ value }) => (value === 1) ? '<i>Day</i>' : '<i>Days</i>'
 }

The function is passed an object with the following properties:

  • source A reference to the field instance.
  • value The current value of the field.

A hintHtml function will be called when the field changes value.

ParameterTypeDescription
dataObject

A data object

data.sourceField

A reference to the field instance

data.value*

The current value of the field

Returns: String
labels: Object[]

The labels to add either before or after the input field. Each label may have the following properties:

  • html The label text.
  • align 'start' or 'end' which end of the field the label should go.
ParameterTypeDescription
htmlString

Label text

alignstart | end

Which end of the file the label should go

labelLabelable
labelClsLabelable
labelPositionLabelable
labelWidthLabelable

Other

autoSelect: Boolean= false

Specify true to auto select field contents on focus

clearable: Boolean | FieldTriggerConfig= false

Show a trigger to clear field, if this field is not readOnly. The trigger is available in the triggers object under the name clear. May also be an object which configures the clear trigger.

Set to false to prevent user from editing the field. For TextFields it is basically the same as setting readOnly, but for PickerFields there is a distinction where it allows you to pick a value but not to type one in the field.

PickerFields such as Combo and DateField can be editable : false, but still modifiable through the UI.

On mobile devices, PickerFields are set to editable : false by default so that the user must select a value from the dropdown picker rather than having to type a value which will cause a display of the virtual keyboard.

If typing is essential to the functioning of the field, configuring the field with editable : true will override this behaviour.

Specify true to highlight field after external value changes

The delay in milliseconds to wait after the last keystroke before triggering a change event. Set to 0 to not trigger change events from keystrokes (listen for input event instead to have immediate feedback, change will still be triggered on blur).

If the field is clearable, the change event fires immediately on receiving the clear gesture.

name: String

Name of the field which is used as a key to get/set values from/to the field. Used prior to ref and id in Container.values.

The config is useful when the field is used in EventEditor or TaskEditor to load/save values automatically.

Text to display in empty field.

Makes the field unmodifiable by user action. The input area is not editable, and triggers are unresponsive.

This is a wider-acting setting than editable which only sets the readOnly attribute of the <input> field.

PickerFields such as Combo and DateField can be editable : false, but still modifiable through the UI.

required: Boolean= falseAlso a property

Configure as true to indicate that a null field value is to be marked as invalid. This will optionally append a * to the field label if showRequiredIndicator is set.

revertOnEscape: Boolean= false

If this field is not readOnly, then setting this option means that pressing the ESCAPE key after editing the field will revert the field to the value it had when the user focused the field. If the field is not changed from when focused, the clearable behaviour will be activated.

true to automatically display a * after the label for this field when it is required.

skipValidation: Boolean= false

Set to true, completely bypasses validation logic (could be userful if your field is not editable to the user).

The triggers to add either before or after the input field. Each property name is the reference by which an instantiated Trigger Widget may be retrieved from the live triggers property.

Each trigger may have the following properties:

  • cls The CSS class to apply.
  • handler A method in the field to call upon click
  • align (Optional) 'start' or 'end' which end of the field the trigger should go.
  • weight (Optional) Higher weighted triggers gravitate towards the input field.
  • key (Optional) The key name of the key to use as the activation key of this trigger.
const textField = new TextField({
  triggers : {
      check : {
          cls : 'fa fa-check',
          handler() {
              ...
          }
      },
      ...
  }
})

Default value

columnWidget
rtlRTL
spanWidget

Accessibility

ariaLabelWidget
keyMapKeyMap

CSS

clsWidget
colorWidget
htmlClsWidget
styleWidget
uiWidget

DOM

adoptWidget
appendToWidget
contentWidget
datasetWidget
htmlWidget
idWidget
tagWidget
titleWidget

Float & align

alignWidget
anchorWidget
centeredWidget
draggableWidget
floatingWidget
xWidget
yWidget

Layout

alignSelfWidget
dockWidget
flexWidget
heightWidget
hiddenWidget
marginWidget
maxHeightWidget
maxWidthWidget
minHeightWidget
minWidthWidget
textAlignWidget
weightWidget
widthWidget

Misc

badgeBadge
dataFieldWidget
disabledWidget
localeClassLocalizable
localizableLocalizable
maskedWidget
ownerWidget
refWidget
rippleWidget
tabWidget
tooltipWidget

Scrolling

Properties

81

Class hierarchy

isField: Boolean= truereadonly
Identifies an object as an instance of Field class, or subclass thereof.
isField: Boolean= truereadonlystatic
Identifies an object as an instance of Field class, or subclass thereof.
isBadgeBadge
isDelayableDelayable
isEventsEvents
isKeyMapKeyMap
isLabelableLabelable
isLocalizableLocalizable
isValidatableValidatable
isWidgetWidget

Other

editable: Boolean= trueAlso a config

Set to false to prevent user from editing the field. For TextFields it is basically the same as setting readOnly, but for PickerFields there is a distinction where it allows you to pick a value but not to type one in the field.

PickerFields such as Combo and DateField can be editable : false, but still modifiable through the UI.

On mobile devices, PickerFields are set to editable : false by default so that the user must select a value from the dropdown picker rather than having to type a value which will cause a display of the virtual keyboard.

If typing is essential to the functioning of the field, configuring the field with editable : true will override this behaviour.

input: HTMLElement

The input element at the heart if this field

isEmpty: Booleanreadonly

Returns true if this field is empty. That is, if it would violate the required setting.

This may have different definitions in subclasses from simple text fields.

isEmptyInput: Booleanreadonly

Returns true if the field's input is empty

isValid: Booleanreadonly

Returns true if the field value is valid

Text to display in empty field.

Makes the field unmodifiable by user action. The input area is not editable, and triggers are unresponsive.

This is a wider-acting setting than editable which only sets the readOnly attribute of the <input> field.

PickerFields such as Combo and DateField can be editable : false, but still modifiable through the UI.

required: Boolean= falseAlso a config

Configure as true to indicate that a null field value is to be marked as invalid. This will optionally append a * to the field label if showRequiredIndicator is set.

true to automatically display a * after the label for this field when it is required.

triggers: Object<String, Widget>Also a config

The triggers to add either before or after the input field. Each property name is the reference by which an instantiated Trigger Widget may be retrieved from the live triggers property.

Each trigger may have the following properties:

  • cls The CSS class to apply.
  • handler A method in the field to call upon click
  • align (Optional) 'start' or 'end' which end of the field the trigger should go.
  • weight (Optional) Higher weighted triggers gravitate towards the input field.
  • key (Optional) The key name of the key to use as the activation key of this trigger.
const textField = new TextField({
  triggers : {
      check : {
          cls : 'fa fa-check',
          handler() {
              ...
          }
      },
      ...
  }
})

Gets or sets the value. The returned type will depend upon the Field subclass.

TextField returns a String.

NumberField returns a Number.

DateField and TimeField return a Date object, and null if the field is empty.

Combo will return a String if configured with items as a simple string array. Otherwise it will return the valueField value from the selected record, or null if no selection has been made.

$namestaticWidget
columnWidget
rtlRTL
spanWidget
typestaticWidget

Accessibility

keyMapKeyMap

CSS

clsWidget

DOM

appendToWidget
contentWidget
datasetWidget
elementWidget
htmlWidget
idWidget
styleWidget

Float & align

xWidget
yWidget

Layout

alignSelfWidget
flexWidget
heightWidget
marginWidget
maxHeightWidget
maxWidthWidget
minHeightWidget
minWidthWidget
widthWidget

Lifecycle

configBase

Misc

badgeBadge
cellInfoWidget
disabledWidget
errorTipValidatable
labelLabelable
localeHelperLocalizable
localeManagerLocalizable
refWidget
tabWidget
tooltipWidget

Visibility

hiddenWidget
isVisibleWidget

Widget hierarchy

ownerWidget
parentWidget

Functions

64

Other

Clears the value of this Field, and triggers the clear event.

Selects the field contents. Optionally may be passed a start and end.

ParameterTypeDescription
startNumber

The start index from which to select the input.

endNumber

The index at which to end the selection of the input.

Called by the base Field class's set value to sync the state of the UI with the field's value.

Relies upon the class implementation of get inputValue to return a string representation of the value for user consumption and editing.

This method can be overridden.

ParameterTypeDescription
skipHighlightBoolean

skip highlighting of the field

Returns: void
clearErrorValidatable
composeWidget
createOnFrameDelayable
disableWidget
enableWidget
focusWidget
getErrorsValidatable
LstaticLocalizable
maskWidget
onEvents
recomposeWidget
relayAllEvents
setErrorValidatable
triggerEvents
unEvents
unmaskWidget

Configuration

applyDefaultsstaticBase

Events

Float & align

alignToWidget
setXYWidget
showByWidget
toFrontWidget

Lifecycle

createstaticWidget
destroystaticBase
initClassstaticWidget

Misc

attachTooltipstaticWidget
fromElementstaticWidget
fromSelectorstaticWidget
getByIdstaticWidget
isOfTypeNamestaticBase
mixinstaticBase
optionalLstaticLocalizable

Visibility

hideWidget
showWidget

Widget hierarchy

closestWidget
containsWidget
ownsWidget
queryWidget
queryAllWidget
upWidget

Events

19

User performed default action (typed into this field).

// Adding a listener using the "on" method
field.on('action', ({ source, value, oldValue, valid, event, record, records, userAction }) => {

});
ParameterTypeDescription
sourceField

This Field

valueString

This field's value

oldValueString

This field's previous value

validBoolean

True if this field is in a valid state

eventEvent

The triggering DOM event if any

recordModel

Selected record. Available for fields with records selection functionality

recordsModel[]

Selected records as an array. Available for fields with records selection functionality

userActionBoolean

Triggered by user taking an action (true) or by setting a value (false)

Fired when this field's value changes.

// Adding a listener using the "on" method
field.on('change', ({ source, value, oldValue, valid, event, userAction }) => {

});
ParameterTypeDescription
sourceField

This Field

valueString

This field's value

oldValueString

This field's previous value

validBoolean

True if this field is in a valid state

eventEvent

The triggering DOM event if any

userActionBoolean

Triggered by user taking an action (true) or by setting a value (false)

Fired when this field is cleared.

This will be triggered when a user clicks this field's clear trigger

// Adding a listener using the "on" method
field.on('clear', ({ source }) => {

});
ParameterTypeDescription
sourceField

This Field

Fired when the user types into this field.

// Adding a listener using the "on" method
field.on('input', ({ source, value, event }) => {

});
ParameterTypeDescription
sourceField

This field

valueString

This field's value

eventEvent

The triggering DOM event

User clicked one of this field's triggers

// Adding a listener using the "on" method
field.on('trigger', ({ source, trigger }) => {

});
ParameterTypeDescription
sourceField

This field

triggerWidget

The trigger activated by click or touch tap.

catchAllEvents
destroyEvents
focusInWidget
focusOutWidget
hideWidget
paintWidget
readOnlyWidget
recomposeWidget
resizeWidget
showWidget

Event handlers

19

User performed default action (typed into this field).

new Field({
    onAction({ source, value, oldValue, valid, event, record, records, userAction }) {

    }
});
ParameterTypeDescription
sourceField

This Field

valueString

This field's value

oldValueString

This field's previous value

validBoolean

True if this field is in a valid state

eventEvent

The triggering DOM event if any

recordModel

Selected record. Available for fields with records selection functionality

recordsModel[]

Selected records as an array. Available for fields with records selection functionality

userActionBoolean

Triggered by user taking an action (true) or by setting a value (false)

Called when this field's value changes.

new Field({
    onChange({ source, value, oldValue, valid, event, userAction }) {

    }
});
ParameterTypeDescription
sourceField

This Field

valueString

This field's value

oldValueString

This field's previous value

validBoolean

True if this field is in a valid state

eventEvent

The triggering DOM event if any

userActionBoolean

Triggered by user taking an action (true) or by setting a value (false)

Called when this field is cleared.

This will be called when a user clicks this field's clear trigger

new Field({
    onClear({ source }) {

    }
});
ParameterTypeDescription
sourceField

This Field

Called when the user types into this field.

new Field({
    onInput({ source, value, event }) {

    }
});
ParameterTypeDescription
sourceField

This field

valueString

This field's value

eventEvent

The triggering DOM event

User clicked one of this field's triggers

new Field({
    onTrigger({ source, trigger }) {

    }
});
ParameterTypeDescription
sourceField

This field

triggerWidget

The trigger activated by click or touch tap.

onDestroyEvents
onFocusInWidget
onHideWidget
onPaintWidget
onResizeWidget
onShowWidget

Typedefs

7

Config object for a field trigger.

ParameterTypeDescription
clsString

The CSS class to apply.

handlerfunction | String

A method in the field to call upon click.

alignstart | end

Which end of the field the trigger should go.

weightNumber

Higher weighted triggers gravitate towards the input field.

keyString

The key name of the key to use as the activation key of this trigger.

AlignSpecWidget
ColorWidget

CSS variables

37
NameDescription
--b-field-label-paddingLabel padding
--b-field-label-default-gapGap between label and field, for the default label position
--b-field-label-above-gapGap between label and field, for label above the field
--b-field-label-before-gapGap between label and field, for label before the field
--b-field-label-before-paddingPadding for label shown before the field
--b-field-label-above-paddingPadding for label shown above the field
--b-field-default-template-areasTemplate areas for the fields grid layout, for the default label position
--b-field-default-template-columnsTemplate columns for the fields grid layout, for the default label position
--b-field-default-label-paddingPadding for label, for the default label position
--b-field-error-tip-primaryPrimary color for tip shown for invalid fields
--b-field-error-tip-colorText color for tip shown for invalid fields
--b-field-error-tip-backgroundBackground for tip shown for invalid fields

Inherited