blockly > FieldVariable

FieldVariable class

Class for a variable's dropdown field.

Signature:

export declare class FieldVariable extends FieldDropdown 

Extends: FieldDropdown

Constructors

Constructor Modifiers Description
(constructor)(varName, validator, variableTypes, defaultType, config) Constructs a new instance of the FieldVariable class

Properties

Property Modifiers Type Description
defaultVariableName string
menuGenerator_ protected MenuGenerator | undefined
SERIALIZABLE boolean Serializable fields are saved by the serializer, non-serializable fields are not. Editable fields should also be serializable.
size_ protected Size
variableTypes string[] | null All of the types of variables that will be available in this field's dropdown.

Methods

Method Modifiers Description
configure_(config) protected Configure the field based on the given map of options.
doClassValidation_(newValue) protected Ensure that the ID belongs to a valid variable of an allowed type.
doValueUpdate_(newId) protected

Update the value of this variable field, as well as its variable and text.

The variable ID should be valid at this point, but if a variable field validator returns a bad ID, this could break.

dropdownCreate(this) static Return a sorted list of variable names for variable dropdown menus. Include a special option at the end for creating a new variable name.
fromXml(fieldElement) Initialize this field based on the given XML.
getText() Get the text from this field, which is the selected variable's name.
getValidator() Gets the validation function for this field, or null if not set. Returns null if the variable is not set, because validators should not run on the initial setValue call, because the field won't be attached to a block and workspace at that point.
getValue() Get the variable's ID.
initModel() Initialize the model for this field if it has not already been initialized. If the value has not been set to a variable by the first render, we make up a variable rather than let the value be invalid.
onItemSelected_(menu, menuItem) protected Handle the selection of an item in the variable dropdown menu. Special case the 'Rename variable...' and 'Delete variable...' options. In the rename case, prompt the user for a new name.
setSourceBlock(block) Attach this field to a block.
shouldAddBorderRect_()
toXml(fieldElement) Serialize this field to XML.