Constructor

FieldImage

new FieldImage(src, width, height, opt_alt, opt_onClick)

Class for an image on a block.

Parameter

src

string

The URL of the image.

width

number

Width of the image.

height

number

Height of the image.

opt_alt

Optional

string

Optional alt text for when block is collapsed.

opt_onClick

Optional

function()

Optional function to be called when the image is clicked. If opt_onClick is defined, opt_alt must also be defined.

Extends
Blockly.Field

Properties

EDITABLE

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

fieldGroup_

SVGElement

imageElement_

SVGElement

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

fromJson

static

fromJson(options) returns Blockly.FieldImage

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

Parameter

options

Object

A JSON object with options (src, width, height, and alt).

Value must not be null.

Returns

non-null Blockly.FieldImage 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

dispose()

Dispose of all DOM objects belonging to this text.

forceRerender

forceRerender()

Images are fixed width, no need to render even if forced.

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.

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 image on a block.

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.

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

The block containing this field.

Value must not be null.

Inherited from
Blockly.Field#setSourceBlock

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

(string or non-null Element)

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

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(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_

showEditor_()

If field click is called, and click handler defined, call the handler.

updateEditable

updateEditable()

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

Inherited from
Blockly.Field#updateEditable