Skip to main content

Class: FieldCheckbox

Defined in: packages/blockly/core/field_checkbox.ts:25

Class for a checkbox field.

Extends

Properties index

PropertyDescription
DEFAULT_VALUETo overwrite the default value which is set in Field, directly update the prototype.
NBSPNon-breaking space.
SKIP_SETUPA value used to signal when a field's constructor should not set the field's value or run configure_, and should allow a subclass to do that instead.
nameName of field. Unique within each block. Static labels are usually unnamed.
validator_Validation function called when user edits an editable field.
ariaTypeNameThe ARIA-friendly label representation of this field's type.
fieldGroup_The rendered field's SVG group element.
borderRect_The rendered field's SVG border element.
textElement_The rendered field's SVG text element.
textContent_The rendered field's text content element.
constants_Constants associated with the source block's renderer.
maxDisplayLengthMaximum characters of text to display before adding an ellipsis.
sourceBlock_Block this field is attached to. Starts as null, then set in init.
isDirty_Does this block need to be re-rendered?
visible_Is the field visible, or hidden due to the block being collapsed?
enabled_Can the field value be changed using the editor on an editable block?
clickTarget_The element the click handler is bound to.
EDITABLEEditable fields usually show some sort of UI indicating they are editable. They will also be saved by the serializer.
CHECK_CHARDefault character for the checkmark.
SERIALIZABLESerializable fields are saved by the serializer, non-serializable fields are not. Editable fields should also be serializable.
value_NOTE: The default value is set in Field, so maintain that value instead of overwriting it here or in the constructor.

Methods index

MethodDescription
setSourceBlockAttach this field to a block.
getConstantsGet the renderer constant provider.
getSourceBlockGet the block this field is attached to.
setAriaTypeNameSets the ARIA-friendly label representation of this field's type.
computeAriaLabelComputes a descriptive ARIA label to represent this field with configurable verbosity.
initModelInitializes the model of the field after it has been installed on a block. No-op by default.
isFullBlockFieldDefines whether this field should take up the full block or not.
createBorderRect_Create a field border rect element. Not to be overridden by subclasses. Instead modify the result of the function inside initView, or create a separate function to call.
createTextElement_Create a field text element. Not to be overridden by subclasses. Instead, modify the result of the function inside initView, or create a separate function to call. Aria state is hidden; use the aria label for the field and/or containing block to expose content to screen readers. Text content for custom blocks can be set after creation.
bindEvents_Bind events to the field. Can be overridden by subclasses if they need to do custom input handling.
fromXmlSets the field's value based on the given XML element. Should only be called by Blockly.Xml.
toXmlSerializes this field's value to XML. Should only be called by Blockly.Xml.
loadStateSets the field's state based on the given state value. Should only be called by the serialization system.
saveLegacyStateReturns a stringified version of the XML state, if it should be used. Otherwise this returns null, to signal the field should use its own serialization.
loadLegacyStateLoads the given state using either the old XML hooks, if they should be used. Returns true to indicate loading has been handled, false otherwise.
disposeDispose of all DOM objects and events belonging to this editable field.
updateEditableAdd or remove the UI indicating if this field is editable or not.
setEnabledSet whether this field's value can be changed using the editor when the source block is editable.
isEnabledCheck whether this field's value can be changed using the editor when the source block is editable.
isClickableCheck whether this field defines the showEditor_ function.
isClickableInFlyoutCheck whether the field should be clickable while the block is in a flyout. The default is that fields are clickable in always-open flyouts such as the simple toolbox, but not in autoclosing flyouts such as the category toolbox. Subclasses may override this function to change this behavior. Note that isClickable must also return true for this to have any effect.
isCurrentlyEditableCheck whether this field is currently editable. Some fields are never EDITABLE (e.g. text labels). Other fields may be EDITABLE but may exist on non-editable blocks or be currently disabled.
isSerializableCheck whether this field should be serialized by the XML renderer. Handles the logic for backwards compatibility and incongruous states.
isVisibleGets whether this editable field is visible or not.
setValidatorSets a new validation function for editable fields, or clears a previously set validator.
getValidatorGets the validation function for editable fields, or null if not set.
getSvgRootGets the group element for this editable field. Used for measuring the size and for positioning.
getBorderRectGets the border rectangle element.
getTextElementGets the text element.
getTextContentGets the text content.
applyColourUpdates the field to match the colour/style of the block.
repositionForWindowResizeA developer hook to reposition the WidgetDiv during a window resize. You need to define this hook if your field has a WidgetDiv that needs to reposition itself when the window is resized. For example, text input fields define this hook so that the input WidgetDiv can reposition itself on a window resize event. This is especially important when modal inputs have been disabled, as Android devices will fire a window resize event when the soft keyboard opens.
updateSize_Updates the size of the field based on the text.
positionTextElement_Position a field's text element after a size change. This handles both LTR and RTL positioning.
positionBorderRect_Position a field's border rect after a size change.
getSizeReturns the height and width of the field.
onLocationChangeNotifies the field that it has changed locations.
getText_A developer hook to override the returned text of this field. Override if the text representation of the value of this field is not just a string cast of its value. Return null to resort to a string cast.
forceRerenderForce a rerender of the block that this field is installed on, which will rerender this field and adjust for any sizing changes. Other fields on the same block will not rerender, because their sizes have already been recorded.
setValueUsed to change the value of the field. Handles validation and events. Subclasses should override doClassValidation_ and doValueUpdate_ rather than this method.
doValueInvalid_Used to notify the field an invalid value was input. Can be overridden by subclasses, see FieldTextInput. No-op by default.
onMouseDown_Handle a pointerdown event on a field.
setTooltipSets the tooltip for this field.
getTooltipReturns the tooltip text for this field.
getClickTarget_The element to bind the click handler to. If not set explicitly, defaults to the SVG root of the field. When this element is clicked on an editable field, the editor will open.
getAbsoluteXY_Return the absolute coordinates of the top-left corner of this field. The origin (0,0) is the top-left corner of the page body.
referencesVariablesWhether this field references any Blockly variables. If true it may need to be handled differently during serialization and deserialization. Subclasses may override this.
refreshVariableNameRefresh the variable name referenced by this field if this field references variables.
getFlipRtlReturns whether or not we should flip the field in RTL.
onShortcutHandles the given keyboard shortcut.
getFocusableElementSee IFocusableNode.getFocusableElement.
getFocusableTreeSee IFocusableNode.getFocusableTree.
onNodeFocusSee IFocusableNode.onNodeFocus.
onNodeBlurSee IFocusableNode.onNodeBlur.
canBeFocusedSee IFocusableNode.canBeFocused.
performActionHandles the user acting on this field via keyboard navigation. Shows and focuses the field editor.
configure_Configure the field based on the given map of options.
initViewCreate the block UI for this checkbox.
render_Used by getSize() to move/resize any DOM elements, and get the new size.
getDisplayText_Get the text from this field to display on the block. May differ from getText due to ellipsis, and other formatting.
setCheckCharacterSet the character used for the check mark.
showEditor_Toggle the state of the checkbox on click.
doClassValidation_Ensure that the input value is valid ('TRUE' or 'FALSE').
doValueUpdate_Update the value of the field, and update the checkElement.
getValueGet the value of this field, either 'TRUE' or 'FALSE'.
getValueBooleanGet the boolean value of this field.
getTextGet the text of this field. Used when the block is collapsed.
getAriaTypeNameGets an ARIA-friendly label representation of this field's type.
getAriaValueGets an ARIA-friendly label representation of this field's value.
recomputeAriaContextCustomizes the label and sets additional aria state.

Constructors

Constructor

new FieldCheckbox(
value?,
validator?,
config?
): FieldCheckbox;

Defined in: packages/blockly/core/field_checkbox.ts:56

Parameters

ParameterTypeDescription
value?typeof SKIP_SETUP | CheckboxBoolThe initial value of the field. Should either be 'TRUE', 'FALSE' or a boolean. Defaults to 'FALSE'. Also accepts Field.SKIP_SETUP if you wish to skip setup (only used by subclasses that want to handle configuration and setting the field value after their own constructors have run).
validator?FieldCheckboxValidatorA function that is called to validate changes to the field's value. Takes in a value ('TRUE' or 'FALSE') & returns a validated value ('TRUE' or 'FALSE'), or null to abort the change.
config?FieldCheckboxConfigA map of options used to configure the field. See the [field creation documentation]https://docs.blockly.com/guides/create-custom-blocks/fields/built-in-fields/checkbox/#creation for a list of properties this parameter supports.

Returns

FieldCheckbox

Overrides

Field.constructor

Properties

DEFAULT_VALUE

DEFAULT_VALUE: CheckboxBool | null = null;

Defined in: packages/blockly/core/field.ts:79

To overwrite the default value which is set in Field, directly update the prototype.

Example: FieldImage.prototype.DEFAULT_VALUE = null;

Inherited from

Field.DEFAULT_VALUE


NBSP

readonly static NBSP: " " = '\u00A0';

Defined in: packages/blockly/core/field.ts:82

Non-breaking space.

Inherited from

Field.NBSP


SKIP_SETUP

readonly static SKIP_SETUP: typeof SKIP_SETUP;

Defined in: packages/blockly/core/field.ts:89

A value used to signal when a field's constructor should not set the field's value or run configure_, and should allow a subclass to do that instead.

Inherited from

Field.SKIP_SETUP


name?

optional name?: string = undefined;

Defined in: packages/blockly/core/field.ts:95

Name of field. Unique within each block. Static labels are usually unnamed.

Inherited from

Field.name


validator_

protected validator_:
| FieldValidator<CheckboxBool>
| null = null;

Defined in: packages/blockly/core/field.ts:99

Validation function called when user edits an editable field.

Inherited from

Field.validator_


ariaTypeName

protected ariaTypeName: string | null = null;

Defined in: packages/blockly/core/field.ts:102

The ARIA-friendly label representation of this field's type.

Inherited from

Field.ariaTypeName


fieldGroup_

protected fieldGroup_: SVGGElement | null = null;

Defined in: packages/blockly/core/field.ts:130

The rendered field's SVG group element.

Inherited from

Field.fieldGroup_


borderRect_

protected borderRect_: SVGRectElement | null = null;

Defined in: packages/blockly/core/field.ts:133

The rendered field's SVG border element.

Inherited from

Field.borderRect_


textElement_

protected textElement_: SVGTextElement | null = null;

Defined in: packages/blockly/core/field.ts:136

The rendered field's SVG text element.

Inherited from

Field.textElement_


textContent_

protected textContent_: Text | null = null;

Defined in: packages/blockly/core/field.ts:139

The rendered field's text content element.

Inherited from

Field.textContent_


constants_

protected constants_:
| ConstantProvider
| null = null;

Defined in: packages/blockly/core/field.ts:145

Constants associated with the source block's renderer.

Inherited from

Field.constants_


maxDisplayLength

maxDisplayLength: number = 50;

Defined in: packages/blockly/core/field.ts:155

Maximum characters of text to display before adding an ellipsis.

Inherited from

Field.maxDisplayLength


sourceBlock_

protected sourceBlock_: Block | null = null;

Defined in: packages/blockly/core/field.ts:158

Block this field is attached to. Starts as null, then set in init.

Inherited from

Field.sourceBlock_


isDirty_

protected isDirty_: boolean = true;

Defined in: packages/blockly/core/field.ts:161

Does this block need to be re-rendered?

Inherited from

Field.isDirty_


visible_

protected visible_: boolean = true;

Defined in: packages/blockly/core/field.ts:164

Is the field visible, or hidden due to the block being collapsed?

Inherited from

Field.visible_


enabled_

protected enabled_: boolean = true;

Defined in: packages/blockly/core/field.ts:169

Can the field value be changed using the editor on an editable block?

Inherited from

Field.enabled_


clickTarget_

protected clickTarget_: Element | null = null;

Defined in: packages/blockly/core/field.ts:172

The element the click handler is bound to.

Inherited from

Field.clickTarget_


EDITABLE

EDITABLE: boolean = true;

Defined in: packages/blockly/core/field.ts:192

Editable fields usually show some sort of UI indicating they are editable. They will also be saved by the serializer.

Inherited from

Field.EDITABLE


CHECK_CHAR

readonly static CHECK_CHAR: "✓" = '✓';

Defined in: packages/blockly/core/field_checkbox.ts:27

Default character for the checkmark.


SERIALIZABLE

SERIALIZABLE: boolean = true;

Defined in: packages/blockly/core/field_checkbox.ts:34

Serializable fields are saved by the serializer, non-serializable fields are not. Editable fields should also be serializable.

Overrides

Field.SERIALIZABLE


value_

value_: boolean | null;

Defined in: packages/blockly/core/field_checkbox.ts:40

NOTE: The default value is set in Field, so maintain that value instead of overwriting it here or in the constructor.

Overrides

Field.value_

Accessors

size_

Get Signature

get protected size_(): Size;

Defined in: packages/blockly/core/field.ts:121

Gets the size of this field. Because getSize() and updateSize() have side effects, this acts as a shim for subclasses which wish to adjust field bounds when setting/getting the size without triggering unwanted rendering or other side effects. Note that subclasses must override both get and set if either is overridden; the implementation may just call directly through to super, but it must exist per the JS spec.

Returns

Size

Set Signature

set protected size_(newValue): void;

Defined in: packages/blockly/core/field.ts:125

Parameters
ParameterType
newValueSize
Returns

void

Inherited from

Field.size_

Methods

setSourceBlock()

setSourceBlock(block): void;

Defined in: packages/blockly/core/field.ts:266

Attach this field to a block.

Parameters

ParameterTypeDescription
blockBlockThe block containing this field.

Returns

void

Inherited from

Field.setSourceBlock


getConstants()

getConstants():
| ConstantProvider
| null;

Defined in: packages/blockly/core/field.ts:284

Get the renderer constant provider.

Returns

| ConstantProvider | null

The renderer constant provider.

Inherited from

Field.getConstants


getSourceBlock()

getSourceBlock(): Block | null;

Defined in: packages/blockly/core/field.ts:304

Get the block this field is attached to.

Returns

Block | null

The block containing this field.

Throws

An error if the source block is not defined.

Inherited from

Field.getSourceBlock


setAriaTypeName()

setAriaTypeName(ariaTypeName): void;

Defined in: packages/blockly/core/field.ts:332

Sets the ARIA-friendly label representation of this field's type.

Implementations are responsible for, and encouraged to, set a localized version of the ARIA representation of the field's type. To that end, the provided value may contain message references of the form %{BKY_...} (e.g. %{BKY_MY_FIELD_ARIA_TYPE}), which are replaced with the corresponding Blockly.Msg value.

Parameters

ParameterTypeDescription
ariaTypeNamestringAn ARIA representation of the field's type.

Returns

void

Inherited from

Field.setAriaTypeName


computeAriaLabel()

computeAriaLabel(includeTypeInfo?): string;

Defined in: packages/blockly/core/field.ts:391

Computes a descriptive ARIA label to represent this field with configurable verbosity.

A 'verbose' label includes type information, if available, whereas a non-verbose label only contains the field's value.

Note that this will always return the latest representation of the field's label which may differ from any previously set ARIA label for the field itself. Implementations are largely responsible for ensuring that the field's ARIA label is set correctly at relevant moments in the field's lifecycle (such as when its value changes).

Finally, it is never guaranteed that implementations use the label returned by this method for their actual ARIA label. Some implementations may rely on other contexts to convey information like the field's value. Example: checkboxes represent their checked/non-checked status (i.e. value) through a separate ARIA property.

If the field's value is empty then it will return a localized placeholder indicating that its value is empty. If this method returns an empty string, the output will be ignored when composing the block-level ARIA label. Make sure you want your label hidden from screenreaders before returning an empty string.

Parameters

ParameterTypeDefault valueDescription
includeTypeInfobooleantrueWhether to include the field's type information in the returned label, if available.

Returns

string

Inherited from

Field.computeAriaLabel


initModel()

initModel(): void;

Defined in: packages/blockly/core/field.ts:454

Initializes the model of the field after it has been installed on a block. No-op by default.

Returns

void

Inherited from

Field.initModel


isFullBlockField()

isFullBlockField(): boolean;

Defined in: packages/blockly/core/field.ts:470

Defines whether this field should take up the full block or not.

This is typically only done for certain kinds of fields and in certain renderers. You should only override this if you're sure your field will render correctly in zelos and other renderers that support full-block fields.

Blocks that contain only a single field that is a full-block-field have a special appearance in some renderers and their behavior is unique, because we pretend that the field is a whole block in some cases. This is hacky and you should use caution when attempting to do anything with this method.

Returns

boolean

Inherited from

Field.isFullBlockField


createBorderRect_()

protected createBorderRect_(): void;

Defined in: packages/blockly/core/field.ts:489

Create a field border rect element. Not to be overridden by subclasses. Instead modify the result of the function inside initView, or create a separate function to call.

Returns

void

Inherited from

Field.createBorderRect_


createTextElement_()

protected createTextElement_(): void;

Defined in: packages/blockly/core/field.ts:512

Create a field text element. Not to be overridden by subclasses. Instead, modify the result of the function inside initView, or create a separate function to call. Aria state is hidden; use the aria label for the field and/or containing block to expose content to screen readers. Text content for custom blocks can be set after creation.

Returns

void

Inherited from

Field.createTextElement_


bindEvents_()

protected bindEvents_(): void;

Defined in: packages/blockly/core/field.ts:532

Bind events to the field. Can be overridden by subclasses if they need to do custom input handling.

Returns

void

Inherited from

Field.bindEvents_


fromXml()

fromXml(fieldElement): void;

Defined in: packages/blockly/core/field.ts:550

Sets the field's value based on the given XML element. Should only be called by Blockly.Xml.

Parameters

ParameterTypeDescription
fieldElementElementThe element containing info about the field's state.

Returns

void

Inherited from

Field.fromXml


toXml()

toXml(fieldElement): Element;

Defined in: packages/blockly/core/field.ts:562

Serializes this field's value to XML. Should only be called by Blockly.Xml.

Parameters

ParameterTypeDescription
fieldElementElementThe element to populate with info about the field's state.

Returns

Element

The element containing info about the field's state.

Inherited from

Field.toXml


loadState()

loadState(state): void;

Defined in: packages/blockly/core/field.ts:594

Sets the field's state based on the given state value. Should only be called by the serialization system.

Parameters

ParameterTypeDescription
stateanyThe state we want to apply to the field.

Returns

void

Inherited from

Field.loadState


saveLegacyState()

protected saveLegacyState(callingClass): string | null;

Defined in: packages/blockly/core/field.ts:610

Returns a stringified version of the XML state, if it should be used. Otherwise this returns null, to signal the field should use its own serialization.

Parameters

ParameterTypeDescription
callingClassFieldProtoThe class calling this method. Used to see if this has overridden any relevant hooks.

Returns

string | null

The stringified version of the XML state, or null.

Inherited from

Field.saveLegacyState


loadLegacyState()

loadLegacyState(callingClass, state): boolean;

Defined in: packages/blockly/core/field.ts:637

Loads the given state using either the old XML hooks, if they should be used. Returns true to indicate loading has been handled, false otherwise.

Parameters

ParameterTypeDescription
callingClassFieldProtoThe class calling this method. Used to see if this has overridden any relevant hooks.
stateanyThe state to apply to the field.

Returns

boolean

Whether the state was applied or not.

Inherited from

Field.loadLegacyState


dispose()

dispose(): void;

Defined in: packages/blockly/core/field.ts:656

Dispose of all DOM objects and events belonging to this editable field.

Returns

void

Inherited from

Field.dispose


updateEditable()

updateEditable(): void;

Defined in: packages/blockly/core/field.ts:675

Add or remove the UI indicating if this field is editable or not.

Returns

void

Inherited from

Field.updateEditable


setEnabled()

setEnabled(enabled): void;

Defined in: packages/blockly/core/field.ts:696

Set whether this field's value can be changed using the editor when the source block is editable.

Parameters

ParameterTypeDescription
enabledbooleanTrue if enabled.

Returns

void

Inherited from

Field.setEnabled


isEnabled()

isEnabled(): boolean;

Defined in: packages/blockly/core/field.ts:707

Check whether this field's value can be changed using the editor when the source block is editable.

Returns

boolean

Whether this field is enabled.

Inherited from

Field.isEnabled


isClickable()

isClickable(): boolean;

Defined in: packages/blockly/core/field.ts:716

Check whether this field defines the showEditor_ function.

Returns

boolean

Whether this field is clickable.

Inherited from

Field.isClickable


isClickableInFlyout()

isClickableInFlyout(autoClosingFlyout): boolean;

Defined in: packages/blockly/core/field.ts:735

Check whether the field should be clickable while the block is in a flyout. The default is that fields are clickable in always-open flyouts such as the simple toolbox, but not in autoclosing flyouts such as the category toolbox. Subclasses may override this function to change this behavior. Note that isClickable must also return true for this to have any effect.

Parameters

ParameterTypeDescription
autoClosingFlyoutbooleantrue if the containing flyout is an auto-closing one.

Returns

boolean

Whether the field should be clickable while the block is in a flyout.

Inherited from

Field.isClickableInFlyout


isCurrentlyEditable()

isCurrentlyEditable(): boolean;

Defined in: packages/blockly/core/field.ts:747

Check whether this field is currently editable. Some fields are never EDITABLE (e.g. text labels). Other fields may be EDITABLE but may exist on non-editable blocks or be currently disabled.

Returns

boolean

Whether this field is currently enabled, editable and on an editable block.

Inherited from

Field.isCurrentlyEditable


isSerializable()

isSerializable(): boolean;

Defined in: packages/blockly/core/field.ts:762

Check whether this field should be serialized by the XML renderer. Handles the logic for backwards compatibility and incongruous states.

Returns

boolean

Whether this field should be serialized or not.

Inherited from

Field.isSerializable


isVisible()

isVisible(): boolean;

Defined in: packages/blockly/core/field.ts:784

Gets whether this editable field is visible or not.

Returns

boolean

True if visible.

Inherited from

Field.isVisible


setValidator()

setValidator(handler): void;

Defined in: packages/blockly/core/field.ts:821

Sets a new validation function for editable fields, or clears a previously set validator.

The validator function takes in the new field value, and returns validated value. The validated value could be the input value, a modified version of the input value, or null to abort the change.

If the function does not return anything (or returns undefined) the new value is accepted as valid. This is to allow for fields using the validated function as a field-level change event notification.

Parameters

ParameterTypeDescription
handlerFieldValidator<CheckboxBool>The validator function or null to clear a previous validator.

Returns

void

Inherited from

Field.setValidator


getValidator()

getValidator():
| FieldValidator<CheckboxBool>
| null;

Defined in: packages/blockly/core/field.ts:830

Gets the validation function for editable fields, or null if not set.

Returns

| FieldValidator<CheckboxBool> | null

Validation function, or null.

Inherited from

Field.getValidator


getSvgRoot()

getSvgRoot(): SVGGElement | null;

Defined in: packages/blockly/core/field.ts:840

Gets the group element for this editable field. Used for measuring the size and for positioning.

Returns

SVGGElement | null

The group element.

Inherited from

Field.getSvgRoot


getBorderRect()

protected getBorderRect(): SVGRectElement;

Defined in: packages/blockly/core/field.ts:850

Gets the border rectangle element.

Returns

SVGRectElement

The border rectangle element.

Throws

An error if the border rectangle element is not defined.

Inherited from

Field.getBorderRect


getTextElement()

protected getTextElement(): SVGTextElement;

Defined in: packages/blockly/core/field.ts:863

Gets the text element.

Returns

SVGTextElement

The text element.

Throws

An error if the text element is not defined.

Inherited from

Field.getTextElement


getTextContent()

protected getTextContent(): Text;

Defined in: packages/blockly/core/field.ts:876

Gets the text content.

Returns

Text

The text content.

Throws

An error if the text content is not defined.

Inherited from

Field.getTextContent


applyColour()

applyColour(): void;

Defined in: packages/blockly/core/field.ts:895

Updates the field to match the colour/style of the block.

Non-abstract sub-classes may wish to implement this if the colour of the field depends on the colour of the block. It will automatically be called at relevant times, such as when the parent block or renderer changes.

See the field documentation for more information, or FieldDropdown for an example.

Returns

void

Inherited from

Field.applyColour


repositionForWindowResize()

repositionForWindowResize(): boolean;

Defined in: packages/blockly/core/field.ts:953

A developer hook to reposition the WidgetDiv during a window resize. You need to define this hook if your field has a WidgetDiv that needs to reposition itself when the window is resized. For example, text input fields define this hook so that the input WidgetDiv can reposition itself on a window resize event. This is especially important when modal inputs have been disabled, as Android devices will fire a window resize event when the soft keyboard opens.

If you want the WidgetDiv to hide itself instead of repositioning, return false. This is the default behavior.

DropdownDivs already handle their own positioning logic, so you do not need to override this function if your field only has a DropdownDiv.

Returns

boolean

True if the field should be repositioned, false if the WidgetDiv should hide itself instead.

Inherited from

Field.repositionForWindowResize


updateSize_()

protected updateSize_(margin?): void;

Defined in: packages/blockly/core/field.ts:962

Updates the size of the field based on the text.

Parameters

ParameterTypeDescription
margin?numbermargin to use when positioning the text element.

Returns

void

Inherited from

Field.updateSize_


positionTextElement_()

protected positionTextElement_(xOffset, contentWidth): void;

Defined in: packages/blockly/core/field.ts:995

Position a field's text element after a size change. This handles both LTR and RTL positioning.

Parameters

ParameterTypeDescription
xOffsetnumberx offset to use when positioning the text element.
contentWidthnumberThe content width.

Returns

void

Inherited from

Field.positionTextElement_


positionBorderRect_()

protected positionBorderRect_(): void;

Defined in: packages/blockly/core/field.ts:1023

Position a field's border rect after a size change.

Returns

void

Inherited from

Field.positionBorderRect_


getSize()

getSize(): Size;

Defined in: packages/blockly/core/field.ts:1046

Returns the height and width of the field.

This should in general be the only place render_ gets called from.

Returns

Size

Height and width.

Inherited from

Field.getSize


onLocationChange()

onLocationChange(_): void;

Defined in: packages/blockly/core/field.ts:1107

Notifies the field that it has changed locations.

Parameters

ParameterTypeDescription
_CoordinateThe location of this field's block's top-start corner in workspace coordinates.

Returns

void

Inherited from

Field.onLocationChange


getText_()

protected getText_(): string | null;

Defined in: packages/blockly/core/field.ts:1156

A developer hook to override the returned text of this field. Override if the text representation of the value of this field is not just a string cast of its value. Return null to resort to a string cast.

Returns

string | null

Current text or null.

Inherited from

Field.getText_


forceRerender()

forceRerender(): void;

Defined in: packages/blockly/core/field.ts:1179

Force a rerender of the block that this field is installed on, which will rerender this field and adjust for any sizing changes. Other fields on the same block will not rerender, because their sizes have already been recorded.

Returns

void

Inherited from

Field.forceRerender


setValue()

setValue(newValue, fireChangeEvent?): void;

Defined in: packages/blockly/core/field.ts:1197

Sealed

Used to change the value of the field. Handles validation and events. Subclasses should override doClassValidation_ and doValueUpdate_ rather than this method.

Parameters

ParameterTypeDefault valueDescription
newValueanyundefinedNew value.
fireChangeEventbooleantrueWhether to fire a change event. Defaults to true. Should usually be true unless the change will be reported some other way, e.g. an intermediate field change event.

Returns

void

Inherited from

Field.setValue


doValueInvalid_()

protected doValueInvalid_(_invalidValue, _fireChangeEvent?): void;

Defined in: packages/blockly/core/field.ts:1352

Used to notify the field an invalid value was input. Can be overridden by subclasses, see FieldTextInput. No-op by default.

Parameters

ParameterTypeDefault valueDescription
_invalidValueanyundefinedThe input value that was determined to be invalid.
_fireChangeEventbooleantrueWhether to fire a change event if the value changes.

Returns

void

Inherited from

Field.doValueInvalid_


onMouseDown_()

protected onMouseDown_(e): void;

Defined in: packages/blockly/core/field.ts:1363

Handle a pointerdown event on a field.

Parameters

ParameterTypeDescription
ePointerEventPointer down event.

Returns

void

Inherited from

Field.onMouseDown_


setTooltip()

setTooltip(newTip): void;

Defined in: packages/blockly/core/field.ts:1381

Sets the tooltip for this field.

Parameters

ParameterTypeDescription
newTipTipInfo | nullThe text for the tooltip, a function that returns the text for the tooltip, a parent object whose tooltip will be used, or null to display the tooltip of the parent block. To not display a tooltip pass the empty string.

Returns

void

Inherited from

Field.setTooltip


getTooltip()

getTooltip(): string;

Defined in: packages/blockly/core/field.ts:1400

Returns the tooltip text for this field.

Returns

string

The tooltip text for this field.

Inherited from

Field.getTooltip


getClickTarget_()

protected getClickTarget_(): Element | null;

Defined in: packages/blockly/core/field.ts:1416

The element to bind the click handler to. If not set explicitly, defaults to the SVG root of the field. When this element is clicked on an editable field, the editor will open.

Returns

Element | null

Element to bind click handler to.

Inherited from

Field.getClickTarget_


getAbsoluteXY_()

protected getAbsoluteXY_(): Coordinate;

Defined in: packages/blockly/core/field.ts:1426

Return the absolute coordinates of the top-left corner of this field. The origin (0,0) is the top-left corner of the page body.

Returns

Coordinate

Object with .x and .y properties.

Inherited from

Field.getAbsoluteXY_


referencesVariables()

referencesVariables(): boolean;

Defined in: packages/blockly/core/field.ts:1437

Whether this field references any Blockly variables. If true it may need to be handled differently during serialization and deserialization. Subclasses may override this.

Returns

boolean

True if this field has any variable references.

Inherited from

Field.referencesVariables


refreshVariableName()

refreshVariableName(): void;

Defined in: packages/blockly/core/field.ts:1445

Refresh the variable name referenced by this field if this field references variables.

Returns

void

Inherited from

Field.refreshVariableName


getFlipRtl()

getFlipRtl(): boolean;

Defined in: packages/blockly/core/field.ts:1481

Returns whether or not we should flip the field in RTL.

Returns

boolean

True if we should flip in RTL.

Inherited from

Field.getFlipRtl


onShortcut()

onShortcut(_shortcut): boolean;

Defined in: packages/blockly/core/field.ts:1491

Handles the given keyboard shortcut.

Parameters

ParameterTypeDescription
_shortcutKeyboardShortcutThe shortcut to be handled.

Returns

boolean

True if the shortcut has been handled, false otherwise.

Inherited from

Field.onShortcut


getFocusableElement()

getFocusableElement(): HTMLElement | SVGElement;

Defined in: packages/blockly/core/field.ts:1496

See IFocusableNode.getFocusableElement.

Returns

HTMLElement | SVGElement

Inherited from

Field.getFocusableElement


getFocusableTree()

getFocusableTree(): IFocusableTree;

Defined in: packages/blockly/core/field.ts:1504

See IFocusableNode.getFocusableTree.

Returns

IFocusableTree

Inherited from

Field.getFocusableTree


onNodeFocus()

onNodeFocus(): void;

Defined in: packages/blockly/core/field.ts:1513

See IFocusableNode.onNodeFocus.

Returns

void

Inherited from

Field.onNodeFocus


onNodeBlur()

onNodeBlur(): void;

Defined in: packages/blockly/core/field.ts:1521

See IFocusableNode.onNodeBlur.

Returns

void

Inherited from

Field.onNodeBlur


canBeFocused()

canBeFocused(): boolean;

Defined in: packages/blockly/core/field.ts:1524

See IFocusableNode.canBeFocused.

Returns

boolean

Inherited from

Field.canBeFocused


performAction()

performAction(): void;

Defined in: packages/blockly/core/field.ts:1532

Handles the user acting on this field via keyboard navigation. Shows and focuses the field editor.

Returns

void

Inherited from

Field.performAction


configure_()

protected configure_(config): void;

Defined in: packages/blockly/core/field_checkbox.ts:84

Configure the field based on the given map of options.

Parameters

ParameterTypeDescription
configFieldCheckboxConfigA map of options to configure the field based on.

Returns

void

Overrides

Field.configure_


initView()

initView(): void;

Defined in: packages/blockly/core/field_checkbox.ts:106

Create the block UI for this checkbox.

Returns

void

Overrides

Field.initView


render_()

render_(): void;

Defined in: packages/blockly/core/field_checkbox.ts:115

Used by getSize() to move/resize any DOM elements, and get the new size.

All rendering that has an effect on the size/shape of the block should be done here, and should be triggered by getSize().

Returns

void

Overrides

Field.render_


getDisplayText_()

getDisplayText_(): string;

Defined in: packages/blockly/core/field_checkbox.ts:122

Get the text from this field to display on the block. May differ from getText due to ellipsis, and other formatting.

Returns

string

Text to display.

Overrides

Field.getDisplayText_


setCheckCharacter()

setCheckCharacter(character): void;

Defined in: packages/blockly/core/field_checkbox.ts:132

Set the character used for the check mark.

Parameters

ParameterTypeDescription
characterstring | nullThe character to use for the check mark, or null to use the default.

Returns

void


showEditor_()

protected showEditor_(): void;

Defined in: packages/blockly/core/field_checkbox.ts:138

Toggle the state of the checkbox on click.

Returns

void

Overrides

Field.showEditor_


doClassValidation_()

protected doClassValidation_(newValue?): BoolString | null;

Defined in: packages/blockly/core/field_checkbox.ts:148

Ensure that the input value is valid ('TRUE' or 'FALSE').

Parameters

ParameterTypeDescription
newValue?anyThe input value.

Returns

BoolString | null

A valid value ('TRUE' or 'FALSE), or null if invalid.

Overrides

Field.doClassValidation_


doValueUpdate_()

protected doValueUpdate_(newValue): void;

Defined in: packages/blockly/core/field_checkbox.ts:166

Update the value of the field, and update the checkElement.

Parameters

ParameterTypeDescription
newValueBoolStringThe value to be saved. The default validator guarantees that this is a either 'TRUE' or 'FALSE'.

Returns

void

Overrides

Field.doValueUpdate_


getValue()

getValue(): BoolString;

Defined in: packages/blockly/core/field_checkbox.ts:180

Get the value of this field, either 'TRUE' or 'FALSE'.

Returns

BoolString

The value of this field.

Overrides

Field.getValue


getValueBoolean()

getValueBoolean(): boolean | null;

Defined in: packages/blockly/core/field_checkbox.ts:189

Get the boolean value of this field.

Returns

boolean | null

The boolean value of this field.


getText()

getText(): string;

Defined in: packages/blockly/core/field_checkbox.ts:198

Get the text of this field. Used when the block is collapsed.

Returns

string

Text representing the value of this field ('true' or 'false').

Overrides

Field.getText


getAriaTypeName()

getAriaTypeName(): string;

Defined in: packages/blockly/core/field_checkbox.ts:225

Gets an ARIA-friendly label representation of this field's type.

Implementations are responsible for, and encouraged to, return a localized version of the ARIA representation of the field's type.

Returns

string

An ARIA representation of the field's type or a default if it is unspecified.

Overrides

Field.getAriaTypeName


getAriaValue()

getAriaValue(): string | null;

Defined in: packages/blockly/core/field_checkbox.ts:241

Gets an ARIA-friendly label representation of this field's value.

Implementations are responsible for, and encouraged to, return a localized version of the ARIA representation of the field's value.

The FieldCheckbox implementation is not used for the actual ARIA label of the field, since the checked state is already included in the ARIA checked state, but it is used for the ARIA label of its source block.

Returns

string | null

An ARIA representation of the field's text.

Overrides

Field.getAriaValue


recomputeAriaContext()

recomputeAriaContext(): boolean;

Defined in: packages/blockly/core/field_checkbox.ts:268

Customizes the label and sets additional aria state.

Returns

boolean

Overrides

Field.recomputeAriaContext