Constructor

FieldVariable

new FieldVariable(varname, opt_validator, opt_variableTypes, opt_defaultType)

Class for a variable's dropdown field.

Parameter

varname

string

The default name for the variable. If null, a unique variable name will be generated.

Value may be null.

opt_validator

Optional

function()

A function that is executed when a new option is selected. Its sole argument is the new option value.

opt_variableTypes

Optional

Array of string

A list of the types of variables to include in the dropdown.

opt_defaultType

Optional

string

The type of variable to create if this field's value is not explicitly set. Defaults to ''.

Extends
Blockly.FieldDropdown

Properties

CURSOR

Mouse cursor style when over the hotspot that initiates the editor.

Inherited from
Blockly.FieldDropdown#CURSOR

EDITABLE

Editable fields are saved by the XML renderer, non-editable fields are not.

Inherited from
Blockly.Field#EDITABLE

maxDisplayLength

unknown

Maximum characters of text to display before adding an ellipsis.

Inherited from
Blockly.Field#maxDisplayLength

name

unknown

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

Inherited from
Blockly.Field#name

textElement_

unknown

Inherited from
Blockly.Field#textElement_

Methods

dropdownCreate

static

dropdownCreate() returns Array of string

Return a sorted list of variable names for variable dropdown menus. Include a special option at the end for creating a new variable name.

Returns

non-null Array of string Array of variable names.

fromJson

static

fromJson(options) returns Blockly.FieldVariable

Construct a FieldVariable from a JSON arg object, dereferencing any string table references.

Parameter

options

Object

A JSON object with options (variable, variableTypes, and defaultType).

Value must not be null.

Returns

non-null Blockly.FieldVariable The new field instance.

callValidator

callValidator(text) returns string

Calls the validation function for this field, as well as all the validation function for the field's class and its parents.

Parameter

text

Proposed text.

Inherited from
Blockly.Field#callValidator
Returns

Revised text, or null if invalid.

classValidator

classValidator(text) returns string

Validates a change. Does nothing. Subclasses may override this.

Parameter

text

The user's text.

Inherited from
Blockly.Field#classValidator
Returns

No change needed.

dispose

public

dispose()

Dispose of this field.

forceRerender

forceRerender()

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.

Inherited from
Blockly.Field#forceRerender

getOptions

getOptions() returns Array of non-null Array

Return a list of the options for this dropdown.

Inherited from
Blockly.FieldDropdown#getOptions
Throws

If generated options are incorrectly structured.

Returns

Array of option tuples: (human-readable text or image, language-neutral name).

getSize

getSize() returns goog.math.Size

Returns the height and width of the field.

Inherited from
Blockly.Field#getSize
Returns

Height and width.

getSvgRoot

getSvgRoot() returns Element

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

Inherited from
Blockly.Field#getSvgRoot
Returns

The group element.

getText

getText() returns string

Get the text from this field, which is the selected variable's name.

Returns

string The selected variable's name, or the empty string if no variable is selected.

getValidator

getValidator() returns function()

Gets the validation function for editable fields.

Inherited from
Blockly.Field#getValidator
Returns

Validation function, or null.

getValue

getValue() returns string

Get the variable's ID.

Returns

string Current variable's ID.

getVariable

getVariable() returns Blockly.VariableModel

Get the variable model for the selected variable. Not guaranteed to be in the variable map on the workspace (e.g. if accessed after the variable has been deleted).

Returns

nullable Blockly.VariableModel the selected variable, or null if none was selected.

init

public

init()

Initialize everything needed to render this field. This includes making sure that the field's value is valid.

initModel

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.

isCurrentlyEditable

isCurrentlyEditable() returns boolean

Check whether this field is currently editable. Some fields are never editable (e.g. text labels). Those fields are not serialized to XML. Other fields may be editable, and therefore serialized, but may exist on non-editable blocks.

Inherited from
Blockly.Field#isCurrentlyEditable
Returns

whether this field is editable and on an editable block

isOptionListDynamic

isOptionListDynamic() returns boolean

Inherited from
Blockly.FieldDropdown#isOptionListDynamic
Returns

True if the option list is generated by a function. Otherwise false.

isVisible

isVisible() returns boolean

Gets whether this editable field is visible or not.

Inherited from
Blockly.Field#isVisible
Returns

True if visible.

onItemSelected

onItemSelected(menu, menuItem)

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.

Parameter

menu

goog.ui.Menu

The Menu component clicked.

Value must not be null.

menuItem

goog.ui.MenuItem

The MenuItem selected within menu.

Value must not be null.

referencesVariables

referencesVariables() returns boolean

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

Inherited from
Blockly.Field#referencesVariables
Returns

True if this field has any variable references.

setSourceBlock

setSourceBlock(block)

Attach this field to a block.

Parameter

block

Blockly.Block

The block containing this field.

Value must not be null.

setText

setText(newText)

Set the text in this field. Trigger a rerender of the source block.

Parameter

newText

New text.

Inherited from
Blockly.Field#setText

setTooltip

setTooltip(_newTip)

Change the tooltip text for this field.

Parameter

_newTip

Text for tooltip or a parent element to link to for its tooltip.

Inherited from
Blockly.Field#setTooltip

setValidator

setValidator(handler)

Sets a new validation function for editable fields.

Parameter

handler

New validation function, or null.

Inherited from
Blockly.Field#setValidator

setValue

setValue(id)

Set the variable ID.

Parameter

id

string

New variable ID, which must reference an existing variable.

setVisible

setVisible(visible)

Sets whether this editable field is visible or not.

Parameter

visible

True if visible.

Inherited from
Blockly.Field#setVisible

updateEditable

updateEditable()

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

Inherited from
Blockly.Field#updateEditable

updateWidth

updateWidth()

Updates the width of the field. Overrides field.prototype.updateWidth to deal with image selections on IE and Edge. If the selected item is not an image, or if the browser is not IE / Edge, this simply calls the parent implementation.

Inherited from
Blockly.FieldDropdown#updateWidth