Constructor

FieldTextInput

new FieldTextInput(text, opt_validator)

Class for an editable text field.

Parameter

text

string

The initial content of the field.

opt_validator

Optional

function()

An optional function that is called to validate any constraints on what the user entered. Takes the new text as an argument and returns either the accepted text, a replacement text, or null to abort the change.

Extends
Blockly.Field

Properties

FONTSIZE

static

Point size of text. Should match blocklyText's font-size in CSS.

htmlInput_

protected   static

HTMLInputElement

The HTML input element for the user to type, or null if no FieldTextInput editor is currently open.

CURSOR

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

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

sourceBlock_

protected

unknown

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

Inherited from
Blockly.Field#sourceBlock_

text_

protected

unknown

Visible text to display.

Inherited from
Blockly.Field#text_

textElement_

unknown

Inherited from
Blockly.Field#textElement_

validator_

protected

unknown

Validation function called when user edits an editable field.

Inherited from
Blockly.Field#validator_

visible_

protected

unknown

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

Inherited from
Blockly.Field#visible_

Methods

fromJson

static

fromJson(options) returns Blockly.FieldTextInput

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

Parameter

options

Object

A JSON object with options (text, class, and spellcheck).

Value must not be null.

Returns

non-null Blockly.FieldTextInput The new field instance.

nonnegativeIntegerValidator

static

nonnegativeIntegerValidator(text) returns string

Ensure that only a nonnegative integer may be entered.

Parameter

text

string

The user's text.

Returns

nullable string A string representing a valid int, or null if invalid.

numberValidator

static

numberValidator(text) returns string

Ensure that only a number may be entered.

Parameter

text

string

The user's text.

Returns

nullable string A string representing a valid number, or null if invalid.

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

dispose()

Close the input widget if this input is being deleted.

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

getDisplayText_

protected

getDisplayText_() returns string

Get the text from this field as displayed on screen. May differ from getText due to ellipsis, and other formatting.

Inherited from
Blockly.Field#getDisplayText_
Returns

Currently displayed text.

getScaledBBox_

protected

getScaledBBox_() returns Object

Returns the bounding box of the rendered field, accounting for workspace scaling.

Inherited from
Blockly.Field#getScaledBBox_
Returns

An object with top, bottom, left, and right in pixels relative to the top left corner of the page (window coordinates).

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.

Inherited from
Blockly.Field#getText
Returns

Current text.

getValidator

getValidator() returns function()

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

Inherited from
Blockly.Field#getValidator
Returns

Validation function, or null.

getValue

getValue() returns string

By default there is no difference between the human-readable text and the language-neutral values. Subclasses (such as dropdown) may define this.

Inherited from
Blockly.Field#getValue
Returns

Current value.

init

init()

Install this field on a block.

Inherited from
Blockly.Field#init

initModel

initModel()

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

Inherited from
Blockly.Field#initModel

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

isVisible

isVisible() returns boolean

Gets whether this editable field is visible or not.

Inherited from
Blockly.Field#isVisible
Returns

True if visible.

onMouseDown_

protected

onMouseDown_(e)

Handle a mouse down event on a field.

Parameter

e

Mouse down event.

Value must not be null.

Inherited from
Blockly.Field#onMouseDown_

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.

render_

protected

render_()

Draws the border with the correct width. Saves the computed width in a property.

Inherited from
Blockly.Field#render_

resizeEditor_

protected

resizeEditor_()

Resize the editor and the underlying block to fit the text.

setSourceBlock

setSourceBlock(block)

Attach this field to a block.

Parameter

block

The block containing this field.

Value must not be null.

Inherited from
Blockly.Field#setSourceBlock

setSpellcheck

setSpellcheck(check)

Set whether this field is spellchecked by the browser.

Parameter

check

boolean

True if checked.

setText

setText(newText)

Set the text in this field and fire a change event.

Parameter

newText

any type

New text.

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, or clears a previously set validator.

The validator function takes in the text form of the users input, and optionally returns the accepted field text. Alternatively, if the function returns null, the field value change aborts. If the function does not return anything (or returns undefined), the input value is accepted as valid. This is a shorthand for fields using the validator function call as a field-level change event notification.

Parameter

handler

The validator function or null to clear a previous validator.

Value may be null.

Inherited from
Blockly.Field#setValidator

setValue

setValue(newValue)

By default there is no difference between the human-readable text and the language-neutral values. Subclasses (such as dropdown) may define this.

Parameter

newValue

New value.

Inherited from
Blockly.Field#setValue

setVisible

setVisible(visible)

Sets whether this editable field is visible or not.

Parameter

visible

True if visible.

Inherited from
Blockly.Field#setVisible

showEditor_

protected

showEditor_(opt_quietInput)

Show the inline free-text editor on top of the text.

Parameter

opt_quietInput

Optional

boolean

True if editor should be created without focus. Defaults to false.

updateEditable

updateEditable()

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

Inherited from
Blockly.Field#updateEditable

updateWidth

updateWidth()

Updates thw width of the field. This calls getCachedWidth which won't cache the approximated width on IE/Edge when getComputedTextLength fails. Once it eventually does succeed, the result will be cached.

Inherited from
Blockly.Field#updateWidth

validate_

protected

validate_()

Check to see if the contents of the editor validates. Style the editor accordingly.