Blockly. FieldNumber
Class for an editable number field.
Constructor
FieldNumber
new FieldNumber(opt_value, opt_min, opt_max, opt_precision, opt_validator, opt_config)
Parameter |
|
---|---|
opt_value |
Optional The initial value of the field. Should cast to a number. Defaults to 0. 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). |
opt_min |
Optional Minimum value. Will only be used if opt_config is not provided. Value may be null. |
opt_max |
Optional Maximum value. Will only be used if opt_config is not provided. Value may be null. |
opt_precision |
Optional Precision for value. Will only be used if opt_config is not provided. Value may be null. |
opt_validator |
Optional A function that is called to validate changes to the field's value. Takes in a number & returns a validated number, or null to abort the change. Value may be null. |
opt_config |
Optional A map of options used to configure the field. See the field creation documentation for a list of properties this parameter supports. |
- Extends
- Blockly.FieldTextInput
Properties
borderRect_
unknown
The rendered field's SVG border element.
- Inherited from
- Blockly.Field#borderRect_
clickTarget_
unknown
The element the click handler is bound to.
- Inherited from
- Blockly.Field#clickTarget_
constants_
unknown
Constants associated with the source block's renderer.
- Inherited from
- Blockly.Field#constants_
CURSOR
unknown
Mouse cursor style when over the hotspot that initiates the editor.
- Inherited from
- Blockly.FieldTextInput#CURSOR
DEFAULT_VALUE
any type
The default value for this field.
disposed
unknown
Has this field been disposed of?
- Inherited from
- Blockly.Field#disposed
EDITABLE
unknown
Editable fields usually show some sort of UI indicating they are editable. They will also be saved by the serializer.
- Inherited from
- Blockly.Field#EDITABLE
enabled_
unknown
Can the field value be changed using the editor on an editable block?
- Inherited from
- Blockly.Field#enabled_
fieldGroup_
unknown
The rendered field's SVG group element.
- Inherited from
- Blockly.Field#fieldGroup_
fullBlockClickTarget_
unknown
Whether the field should consider the whole parent block to be its click target.
- Inherited from
- Blockly.FieldTextInput#fullBlockClickTarget_
htmlInput_
unknown
The HTML input element.
- Inherited from
- Blockly.FieldTextInput#htmlInput_
isDirty_
unknown
Does this block need to be re-rendered?
- Inherited from
- Blockly.Field#isDirty_
max_
number
The maximum value this number field can contain.
maxDisplayLength
unknown
Maximum characters of text to display before adding an ellipsis.
- Inherited from
- Blockly.Field#maxDisplayLength
min_
number
The minimum value this number field can contain.
name
unknown
Name of field. Unique within each block. Static labels are usually unnamed.
- Inherited from
- Blockly.Field#name
precision_
number
The multiple to which this fields value is rounded.
prefixField
unknown
The prefix field.
- Inherited from
- Blockly.Field#prefixField
SERIALIZABLE
boolean
Serializable fields are saved by the serializer, non-serializable fields are not. Editable fields should also be serializable.
size_
unknown
The size of the area rendered by the field.
- Inherited from
- Blockly.Field#size_
sourceBlock_
unknown
- Inherited from
- Blockly.FieldTextInput#sourceBlock_
spellcheck_
unknown
Allow browser to spellcheck this field.
- Inherited from
- Blockly.FieldTextInput#spellcheck_
suffixField
unknown
The suffix field.
- Inherited from
- Blockly.Field#suffixField
textContent_
unknown
The rendered field's text content element.
- Inherited from
- Blockly.Field#textContent_
textElement_
unknown
The rendered field's SVG text element.
- Inherited from
- Blockly.Field#textElement_
validator_
unknown
Validation function called when user edits an editable field.
- Inherited from
- Blockly.Field#validator_
value_
unknown
A generic value possessed by the field. Should generally be non-null, only null when the field is created.
- Inherited from
- Blockly.Field#value_
visible_
unknown
Is the field visible, or hidden due to the block being collapsed?
- Inherited from
- Blockly.Field#visible_
workspace_
unknown
The workspace that this field belongs to.
- Inherited from
- Blockly.FieldTextInput#workspace_
Methods
fromJson
fromJson(options) returns Blockly.FieldNumber
Construct a FieldNumber from a JSON arg object.
Parameter |
|
---|---|
options |
Object A JSON object with options (value, min, max, and precision). Value must not be null. |
- Returns
-
non-null Blockly.FieldNumber
The new field instance.
applyColour
applyColour()
Updates text field to match the colour/style of the block.
- Inherited from
- Blockly.FieldTextInput#applyColour
bindEvents_
bindEvents_()
Bind events to the field. Can be overridden by subclasses if they need to do custom input handling.
- Inherited from
- Blockly.Field#bindEvents_
bindInputEvents_
bindInputEvents_(htmlInput)
Bind handlers for user input on the text input field's editor.
Parameter |
|
---|---|
htmlInput |
The htmlInput to which event handlers will be bound. Value must not be null. |
- Inherited from
- Blockly.FieldTextInput#bindInputEvents_
createBorderRect_
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.
- Inherited from
- Blockly.Field#createBorderRect_
createTextElement_
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.
- Inherited from
- Blockly.Field#createTextElement_
dispose
dispose()
Dispose of all DOM objects and events belonging to this editable field.
- Inherited from
- Blockly.Field#dispose
doClassValidation_
doClassValidation_(opt_newValue) returns number
Ensure that the input value is a valid number (must fulfill the constraints placed on the field).
Parameter |
|
---|---|
opt_newValue |
Optional The input value. |
- Inherited from
- Blockly.FieldNumber#doClassValidation_
- Returns
-
A valid number, or null if invalid.
doValueInvalid_
doValueInvalid_(_invalidValue)
Called by setValue if the text input is not valid. If the field is currently being edited it reverts value of the field to the previous value while allowing the display text to be handled by the htmlInput_.
Parameter |
|
---|---|
_invalidValue |
The input value that was determined to be invalid. This is not used by the text input because its display value is stored on the htmlInput_. |
- Inherited from
- Blockly.FieldTextInput#doValueInvalid_
doValueUpdate_
doValueUpdate_(newValue)
Called by setValue if the text input is valid. Updates the value of the field, and updates the text of the field if it is not currently being edited (i.e. handled by the htmlInput_).
Parameter |
|
---|---|
newValue |
The value to be saved. The default validator guarantees that this is a string. |
- Inherited from
- Blockly.FieldTextInput#doValueUpdate_
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
fromXml
fromXml(fieldElement)
Sets the field's value based on the given XML element. Should only be called by Blockly.Xml.
Parameter |
|
---|---|
fieldElement |
The element containing info about the field's state. Value must not be null. |
- Inherited from
- Blockly.Field#fromXml
getAbsoluteXY_
getAbsoluteXY_() returns Blockly.utils.Coordinate
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.
- Inherited from
- Blockly.Field#getAbsoluteXY_
- Returns
-
Object with .x and .y properties.
getClickTarget_
getClickTarget_() returns Element
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.
- Inherited from
- Blockly.Field#getClickTarget_
- Returns
-
Element to bind click handler to.
getConstants
getConstants() returns Blockly.blockRendering.ConstantProvider
Get the renderer constant provider.
- Inherited from
- Blockly.Field#getConstants
- Returns
-
The renderer constant provider.
getDisplayText_
getDisplayText_() returns string
Get the text from this field to display on the block. May differ from
getText
due to ellipsis, and other formatting.
- Inherited from
- Blockly.Field#getDisplayText_
- Returns
-
Text to display.
getEditorText_
getEditorText_(value) returns string
Transform the provided value into a text to show in the HTML input.
Override this method if the field's HTML input representation is different
than the field's value. This should be coupled with an override of
getValueFromEditorText_
.
Parameter |
|
---|---|
value |
The value stored in this field. |
- Inherited from
- Blockly.FieldTextInput#getEditorText_
- Returns
-
The text to show on the HTML input.
getFlipRtl
getFlipRtl() returns boolean
Returns whether or not we should flip the field in RTL.
- Inherited from
- Blockly.Field#getFlipRtl
- Returns
-
True if we should flip in RTL.
getMax
getMax() returns number
Returns the current maximum value this field can contain. Default is Infinity.
- Returns
-
number
The current maximum value this field can contain.
getMin
getMin() returns number
Returns the current minimum value this field can contain. Default is -Infinity.
- Returns
-
number
The current minimum value this field can contain.
getParentInput
getParentInput() returns Blockly.Input
Search through the list of inputs and their fields in order to find the parent input of a field.
- Inherited from
- Blockly.Field#getParentInput
- Returns
-
The input that the field belongs to.
getPrecision
getPrecision() returns number
Returns the current precision of this field. The precision being the number to which the field's value is rounded. A precision of 0 means that the value is not rounded.
- Returns
-
number
The number to which this field's value is rounded.
getScaledBBox
getScaledBBox() returns Blockly.utils.Rect
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 Blockly.utils.Size
Returns the height and width of the field.
This should in general be the only place render_ gets called from.
- Inherited from
- Blockly.Field#getSize
- Returns
-
Height and width.
getSourceBlock
getSourceBlock() returns Blockly.Block
Get the block this field is attached to.
- Inherited from
- Blockly.Field#getSourceBlock
- Implements
- Blockly.IASTNodeLocationWithBlock#getSourceBlock
- Returns
-
The block containing this field.
getSvgRoot
getSvgRoot() returns SVGGElement
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. Override getText_ to provide a different behavior than simply casting the value to a string.
- Inherited from
- Blockly.Field#getText
- Returns
-
Current text.
getTooltip
getTooltip() returns string
Returns the tooltip text for this field.
- Inherited from
- Blockly.Field#getTooltip
- Returns
-
The tooltip text for this field.
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 any type
Get the current value of the field.
- Inherited from
- Blockly.Field#getValue
- Returns
-
Current value.
getValueFromEditorText_
getValueFromEditorText_(text) returns any type
Transform the text received from the HTML input into a value to store
in this field.
Override this method if the field's HTML input representation is different
than the field's value. This should be coupled with an override of
getEditorText_
.
Parameter |
|
---|---|
text |
Text received from the HTML input. |
- Inherited from
- Blockly.FieldTextInput#getValueFromEditorText_
- Returns
-
The value to store.
init
init()
Initialize everything to render this field. Override methods initModel and initView rather than this method.
- 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
isClickable
isClickable() returns boolean
Check whether this field defines the showEditor_ function.
- Inherited from
- Blockly.Field#isClickable
- Returns
-
Whether this field is clickable.
isCurrentlyEditable
isCurrentlyEditable() returns boolean
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.
- Inherited from
- Blockly.Field#isCurrentlyEditable
- Returns
-
Whether this field is currently enabled, editable and on an editable block.
isEnabled
isEnabled() returns boolean
Check whether this field's value can be changed using the editor when the source block is editable.
- Inherited from
- Blockly.Field#isEnabled
- Returns
-
Whether this field is enabled.
isSerializable
isSerializable() returns boolean
Check whether this field should be serialized by the XML renderer. Handles the logic for backwards compatibility and incongruous states.
- Inherited from
- Blockly.Field#isSerializable
- Returns
-
Whether this field should be serialized or not.
isVisible
isVisible() returns boolean
Gets whether this editable field is visible or not.
- Inherited from
- Blockly.Field#isVisible
- Returns
-
True if visible.
loadLegacyState
loadLegacyState(callingClass, state) returns boolean
Loads the given state using either the old XML hoooks, if they should be used. Returns true to indicate loading has been handled, false otherwise.
Parameter |
|
---|---|
callingClass |
The class calling this method.
Used to see if |
state |
The state to apply to the field. |
- Inherited from
- Blockly.Field#loadLegacyState
- Returns
-
Whether the state was applied or not.
loadState
loadState(state)
Sets the field's state based on the given state value. Should only be called by the serialization system.
Parameter |
|
---|---|
state |
The state we want to apply to the field. |
- Inherited from
- Blockly.Field#loadState
markDirty
markDirty()
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#markDirty
onFinishEditing_
onFinishEditing_(_value)
A callback triggered when the user is done editing the field via the UI.
Parameter |
|
---|---|
_value |
The new value of the field. |
- Inherited from
- Blockly.FieldTextInput#onFinishEditing_
onHtmlInputKeyDown_
onHtmlInputKeyDown_(e)
Handle key down to the editor.
Parameter |
|
---|---|
e |
Keyboard event. Value must not be null. |
- Inherited from
- Blockly.FieldTextInput#onHtmlInputKeyDown_
onMouseDown_
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_
onShortcut
onShortcut(_shortcut) returns boolean
Handles the given keyboard shortcut.
Parameter |
|
---|---|
_shortcut |
The shortcut to be handled. Value must not be null. |
- Inherited from
- Blockly.Field#onShortcut
- Implements
- Blockly.IKeyboardAccessible#onShortcut
- Returns
-
True if the shortcut has been handled, false otherwise.
positionBorderRect_
positionBorderRect_()
Position a field's border rect after a size change.
- Inherited from
- Blockly.Field#positionBorderRect_
positionTextElement_
positionTextElement_(xOffset, contentWidth)
Position a field's text element after a size change. This handles both LTR and RTL positioning.
Parameter |
|
---|---|
xOffset |
x offset to use when positioning the text element. |
contentWidth |
The content width. |
- Inherited from
- Blockly.Field#positionTextElement_
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.
refreshVariableName
refreshVariableName()
Refresh the variable name referenced by this field if this field references variables.
- Inherited from
- Blockly.Field#refreshVariableName
render_
render_()
Updates the colour of the htmlInput given the current validity of the field's value.
- Inherited from
- Blockly.FieldTextInput#render_
resizeEditor_
resizeEditor_()
Resize the editor to fit the text.
- Inherited from
- Blockly.FieldTextInput#resizeEditor_
saveLegacyState
saveLegacyState(callingClass) returns string
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.
Parameter |
|
---|---|
callingClass |
The class calling this method.
Used to see if |
- Inherited from
- Blockly.Field#saveLegacyState
- Returns
-
The stringified version of the XML state, or null.
saveState
saveState(_doFullSerialization) returns any type
Saves this fields value as something which can be serialized to JSON. Should only be called by the serialization system.
Parameter |
|
---|---|
_doFullSerialization |
Optional If true, this signals to the field that if it normally just saves a reference to some state (eg variable fields) it should instead serialize the full state of the thing being referenced. |
- Inherited from
- Blockly.Field#saveState
- Returns
-
JSON serializable state.
setConstraints
setConstraints(min, max, precision)
Set the maximum, minimum and precision constraints on this field. Any of these properties may be undefined or NaN to be disabled. Setting precision (usually a power of 10) enforces a minimum step between values. That is, the user's value will rounded to the closest multiple of precision. The least significant digit place is inferred from the precision. Integers values can be enforces by choosing an integer precision.
Parameter |
|
---|---|
min |
(number, string, or undefined) Minimum value. Value may be null. |
max |
(number, string, or undefined) Maximum value. Value may be null. |
precision |
(number, string, or undefined) Precision for value. Value may be null. |
setCursorSvg
setCursorSvg(cursorSvg)
Add the cursor SVG to this fields SVG group.
Parameter |
|
---|---|
cursorSvg |
The SVG root of the cursor to be added to the field group. |
- Inherited from
- Blockly.Field#setCursorSvg
- Implements
- Blockly.IASTNodeLocationSvg#setCursorSvg
setEditorValue_
setEditorValue_(newValue)
Set the HTML input value and the field's internal value. The difference
between this and setValue
is that this also updates the HTML input
value whilst editing.
Parameter |
|
---|---|
newValue |
New value. |
- Inherited from
- Blockly.FieldTextInput#setEditorValue_
setEnabled
setEnabled(enabled)
Set whether this field's value can be changed using the editor when the source block is editable.
Parameter |
|
---|---|
enabled |
True if enabled. |
- Inherited from
- Blockly.Field#setEnabled
setMarkerSvg
setMarkerSvg(markerSvg)
Add the marker SVG to this fields SVG group.
Parameter |
|
---|---|
markerSvg |
The SVG root of the marker to be added to the field group. |
- Inherited from
- Blockly.Field#setMarkerSvg
- Implements
- Blockly.IASTNodeLocationSvg#setMarkerSvg
setMax
setMax(max)
Sets the maximum value this field can contain. Updates the value to reflect.
Parameter |
|
---|---|
max |
(number, string, or undefined) Maximum value. Value may be null. |
setMin
setMin(min)
Sets the minimum value this field can contain. Updates the value to reflect.
Parameter |
|
---|---|
min |
(number, string, or undefined) Minimum value. Value may be null. |
setPrecision
setPrecision(precision)
Sets the precision of this field's value, i.e. the number to which the value is rounded. Updates the field to reflect.
Parameter |
|
---|---|
precision |
(number, string, or undefined) The number to which the field's value is rounded. Value may be null. |
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 |
True if checked. |
- Inherited from
- Blockly.FieldTextInput#setSpellcheck
setTooltip
setTooltip(newTip)
Sets the tooltip for this field.
Parameter |
|
---|---|
newTip |
The 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. Value may be null. |
- 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 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.
Parameter |
|
---|---|
handler |
The validator function or null to clear a previous validator. |
- Inherited from
- Blockly.Field#setValidator
setValue
setValue(newValue)
Used to change the value of the field. Handles validation and events. Subclasses should override doClassValidation_ and doValueUpdate_ rather than this method.
Parameter |
|
---|---|
newValue |
New value. |
- Inherited from
- Blockly.Field#setValue
setVisible
setVisible(visible)
Sets whether this editable field is visible or not. Should only be called by input.setVisible.
Parameter |
|
---|---|
visible |
True if visible. |
- Inherited from
- Blockly.Field#setVisible
showEditor
showEditor(opt_e)
Calls showEditor_ when the field is clicked if the field is clickable. Do not override.
Parameter |
|
---|---|
opt_e |
Optional Optional mouse event that triggered the field to open, or undefined if triggered programmatically. |
- Inherited from
- Blockly.Field#showEditor
showEditor_
showEditor_(_opt_e, opt_quietInput)
Show the inline free-text editor on top of the text.
Parameter |
|
---|---|
_opt_e |
Optional Optional mouse event that triggered the field to open, or undefined if triggered programmatically. |
opt_quietInput |
Optional True if editor should be created without focus. Defaults to false. |
- Inherited from
- Blockly.FieldTextInput#showEditor_
toXml
toXml(fieldElement) returns Element
Serializes this field's value to XML. Should only be called by Blockly.Xml.
Parameter |
|
---|---|
fieldElement |
The element to populate with info about the field's state. Value must not be null. |
- Inherited from
- Blockly.Field#toXml
- Returns
-
The element containing info about the field's state.
unbindInputEvents_
unbindInputEvents_()
Unbind handlers for user input and workspace size changes.
- Inherited from
- Blockly.FieldTextInput#unbindInputEvents_
updateEditable
updateEditable()
Add or remove the UI indicating if this field is editable or not.
- Inherited from
- Blockly.Field#updateEditable
updateMarkers_
updateMarkers_()
Redraw any attached marker or cursor svgs if needed.
- Inherited from
- Blockly.Field#updateMarkers_
updateSize_
updateSize_(opt_margin)
Updates the size of the field based on the text.
Parameter |
|
---|---|
opt_margin |
Optional margin to use when positioning the text element. |
- Inherited from
- Blockly.Field#updateSize_
widgetCreate_
widgetCreate_() returns HTMLElement
Create the number input editor widget.
- Inherited from
- Blockly.FieldNumber#widgetCreate_
- Returns
-
The newly created number input editor.
widgetDispose_
widgetDispose_()
Closes the editor, saves the results, and disposes of any events or DOM-references belonging to the editor.
- Inherited from
- Blockly.FieldTextInput#widgetDispose_