Class: FieldDependentDropdown
Defined in: plugins/field-dependent-dropdown/src/field_dependent_dropdown.ts:62
A dropdown field that automatically updates its own options based on a mapping from a parent field's value. The parent field must be attached to the block before this child field.
When this field is attached to a block, it will find the parent field and
attach a validator to the parent field that intercepts changes to its value
to update the options on this field. If the new validator is later removed
or replaced, then this dependent field will no longer function.
Extends
FieldDropdown
Properties index
| Property | Description |
|---|---|
| ariaTypeName | The ARIA-friendly label representation of this field's type. |
| borderRect_ | The rendered field's SVG border element. |
| clickTarget_ | The element the click handler is bound to. |
| constants_ | Constants associated with the source block's renderer. |
| DEFAULT_VALUE | To overwrite the default value which is set in Field, directly update the prototype. |
| dependencyData | Contains data used by this dropdown field's menu generator. |
| EDITABLE | Editable fields usually show some sort of UI indicating they are editable. They will also be saved by the serializer. |
| enabled_ | Can the field value be changed using the editor on an editable block? |
| fieldGroup_ | The rendered field's SVG group element. |
| isDirty_ | Does this block need to be re-rendered? |
| isInitialized | True once the field’s DOM has been created and it is safe to run ARIA updates in response to value changes. |
| maxDisplayLength | Maximum characters of text to display before adding an ellipsis. |
| menu_ | The dropdown menu. |
| menuGenerator_ | - |
| name | Name of field. Unique within each block. Static labels are usually unnamed. |
| SERIALIZABLE | Serializable fields are saved by the serializer, non-serializable fields are not. Editable fields should also be serializable. |
| sourceBlock_ | Block this field is attached to. Starts as null, then set in init. |
| textContent_ | The rendered field's text content element. |
| textElement_ | The rendered field's SVG text element. |
| validator_ | Validation function called when user edits an editable field. |
| value_ | - |
| visible_ | Is the field visible, or hidden due to the block being collapsed? |
| ARROW_CHAR | - |
| IMAGE_Y_OFFSET | The y offset from the top of the field to the top of the image, if an image is selected. |
| IMAGE_Y_PADDING | The total vertical padding above and below an image. |
| NBSP | Non-breaking space. |
| SEPARATOR | Magic constant used to represent a separator in a list of dropdown items. |
| SKIP_SETUP | A value used to signal when a field's constructor should not set the field's value or run configure_, and should allow a subclass to do that instead. |
Methods index
| Method | Description |
|---|---|
| applyColour | Updates the dropdown arrow to match the colour/style of the block. |
| bindEvents_ | Bind events to the field. Can be overridden by subclasses if they need to do custom input handling. |
| canBeFocused | See IFocusableNode.canBeFocused. |
| computeAriaLabel | Computes a descriptive ARIA label to represent this field with configurable verbosity. |
| configure_ | Process the configuration map passed to the field. |
| 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. |
| createSVGArrow_ | Create an SVG based arrow. |
| createTextArrow_ | Create a tspan based arrow. |
| 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. Aria state is hidden; use the aria label for the field and/or containing block to expose content to screen readers. Text content for custom blocks can be set after creation. |
| dispose | Dispose of all DOM objects and events belonging to this editable field. |
| doClassValidation_ | Ensure that the input value is a valid language-neutral option. |
| doValueInvalid_ | Used to notify the field an invalid value was input. Can be overridden by subclasses, see FieldTextInput. No-op by default. |
| doValueUpdate_ | Update the value of this dropdown field. |
| dropdownDispose_ | Disposes of events and DOM-references belonging to the dropdown editor. |
| 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. |
| getAbsoluteXY_ | 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. |
| getAriaTypeName | Gets an ARIA-friendly label representation of this field's type. |
| getAriaValue | Gets an ARIA-friendly label representation of this field's value. |
| getBorderRect | Gets the border rectangle element. |
| getClickTarget_ | 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. |
| getConstants | Get the renderer constant provider. |
| getDisplayText_ | Get the text from this field to display on the block. May differ from getText due to ellipsis, and other formatting. |
| getFlipRtl | Returns whether or not we should flip the field in RTL. |
| getFocusableElement | See IFocusableNode.getFocusableElement. |
| getFocusableTree | See IFocusableNode.getFocusableTree. |
| getOptions | Return a list of the options for this dropdown. |
| getSize | Returns the height and width of the field. |
| getSourceBlock | Get the block this field is attached to. |
| getSvgRoot | Gets the group element for this editable field. Used for measuring the size and for positioning. |
| getText | Get the text from this field. Override getText_ to provide a different behavior than simply casting the value to a string. |
| getText_ | Use the getText_ developer hook to override the field's text representation. Get the selected option text. If the selected option is an image we return the image alt text. If the selected option is an HTMLElement, return the title, ariaLabel, or innerText of the element. |
| getTextContent | Gets the text content. |
| getTextElement | Gets the text element. |
| getTooltip | Returns the tooltip text for this field. |
| getValidator | Gets the validation function for editable fields, or null if not set. |
| getValue | Get the current value of the field. |
| initModel | Initializes the model of the field after it has been installed on a block. No-op by default. |
| initView | Create the block UI for this dropdown. |
| isClickable | Check whether this field defines the showEditor_ function. |
| isClickableInFlyout | Check whether the field should be clickable while the block is in a flyout. The default is that fields are clickable in always-open flyouts such as the simple toolbox, but not in autoclosing flyouts such as the category toolbox. Subclasses may override this function to change this behavior. Note that isClickable must also return true for this to have any effect. |
| isCurrentlyEditable | 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. |
| isEnabled | Check whether this field's value can be changed using the editor when the source block is editable. |
| isFullBlockField | This is hacky way of determining if a dropdown field is a full-block field or not. The constants that control the border rect are the same ones that determine how we render full-block dropdown fields. It's a full-block field if it doesn't have the border rect (and it's a simple reporter block). |
| isOptionListDynamic | Returns true if the option list is generated by a function. Otherwise false. |
| isSerializable | Check whether this field should be serialized by the XML renderer. Handles the logic for backwards compatibility and incongruous states. |
| isVisible | Gets whether this editable field is visible or not. |
| loadLegacyState | Loads the given state using either the old XML hooks, if they should be used. Returns true to indicate loading has been handled, false otherwise. |
| onItemSelected_ | Handle the selection of an item in the dropdown menu. |
| onLocationChange | Notifies the field that it has changed locations. |
| onMouseDown_ | Handle a pointerdown event on a field. |
| onNodeBlur | See IFocusableNode.onNodeBlur. |
| onNodeFocus | See IFocusableNode.onNodeFocus. |
| onShortcut | Handles the given keyboard shortcut. |
| performAction | Handles the user acting on this field via keyboard navigation. Shows and focuses the field editor. |
| positionBorderRect_ | Position a field's border rect after a size change. |
| positionTextElement_ | Position a field's text element after a size change. This handles both LTR and RTL positioning. |
| recomputeAriaContext | Sets additional aria state. |
| referencesVariables | Whether this field references any Blockly variables. If true it may need to be handled differently during serialization and deserialization, and this field's value must correspond to the ID of an existing variable. Subclasses may override this. |
| refreshVariableName | Refresh the variable name referenced by this field if this field references variables. |
| render_ | Draws the border with the correct width. |
| repositionForWindowResize | A developer hook to reposition the WidgetDiv during a window resize. You need to define this hook if your field has a WidgetDiv that needs to reposition itself when the window is resized. For example, text input fields define this hook so that the input WidgetDiv can reposition itself on a window resize event. This is especially important when modal inputs have been disabled, as Android devices will fire a window resize event when the soft keyboard opens. |
| saveLegacyState | 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. |
| saveState | Saves this fields value as something which can be serialized to JSON. Should only be called by the serialization system. |
| setAriaTypeName | Sets the ARIA-friendly label representation of this field's type. |
| setEnabled | Set whether this field's value can be changed using the editor when the source block is editable. |
| setOptions | Update the options on this dropdown. This will reset the selected item to the first item in the list. |
| setSourceBlock | Attach this field to a block. |
| setTooltip | Sets the tooltip for this field. |
| setValidator | Sets a new validation function for editable fields, or clears a previously set validator. |
| setValue | Used to change the value of the field. Handles validation and events. Subclasses should override doClassValidation_ and doValueUpdate_ rather than this method. |
| shouldAddBorderRect_ | Whether or not the dropdown should add a border rect. |
| showEditor_ | Create a dropdown menu under the text. |
| toXml | Serializes this field's value to XML. Should only be called by Blockly.Xml. |
| trimOptions | Factor out common words in statically defined options. Create prefix and/or suffix labels. |
| updateEditable | Add or remove the UI indicating if this field is editable or not. |
| updateSize_ | Updates the size of the field based on the text. |
| validateOptions | Validates the data structure to be processed as an options list. |
| fromJson | Constructs a FieldDependentDropdown from a JSON arg object. |
Constructors
Constructor
new FieldDependentDropdown(
parentName,
optionMapping,
defaultOptions?,
validator?,
config?
): FieldDependentDropdown;
Defined in: plugins/field-dependent-dropdown/src/field_dependent_dropdown.ts:109
Constructs a new FieldDependentDropdown.
Parameters
| Parameter | Type | Description |
|---|---|---|
parentName | string | The name of the parent field whose value determines this field's available options. |
optionMapping | ChildOptionMapping | A mapping from the possible values of the parent field to the corresponding available options of this child field. The keys are the possible values of the parent field, and the values are the corresponding arrays of options for this child field. |
defaultOptions? | MenuOption[] | An optional fallback set of options to use if the parent field's value does not match any of the keys in optionMapping. |
validator? | FieldValidator | An optional function that is called to validate changes to this field's value. |
config? | FieldConfig | An optional map of general options used to configure the field, such as a tooltip. |
Returns
FieldDependentDropdown
Overrides
Blockly.FieldDropdown.constructor
Properties
ariaTypeName
protected ariaTypeName: string | null;
The ARIA-friendly label representation of this field's type.
Inherited from
Blockly.FieldDropdown.ariaTypeName
borderRect_
protected borderRect_: SVGRectElement | null;
The rendered field's SVG border element.
Inherited from
Blockly.FieldDropdown.borderRect_
clickTarget_
clickTarget_: SVGElement | null;
The element the click handler is bound to.
Inherited from
Blockly.FieldDropdown.clickTarget_
constants_
protected constants_: ConstantProvider | null;
Constants associated with the source block's renderer.
Inherited from
Blockly.FieldDropdown.constants_
DEFAULT_VALUE
DEFAULT_VALUE: string | null;
To overwrite the default value which is set in Field, directly update the prototype.
Example:
FieldImage.prototype.DEFAULT_VALUE = null;
Inherited from
Blockly.FieldDropdown.DEFAULT_VALUE
dependencyData
dependencyData: DependencyData;
Defined in: plugins/field-dependent-dropdown/src/field_dependent_dropdown.ts:74
Contains data used by this dropdown field's menu generator.
The menu generator cannot refer directly to this FieldDependentDropdown instance, because it must be created before calling the super constructor when the "this" reference is not yet valid. This helper structure is used instead.
This is public so that the DependentDropdownOptionsChangeJson event can update it while undoing/redoing.
EDITABLE
EDITABLE: boolean;
Editable fields usually show some sort of UI indicating they are editable. They will also be saved by the serializer.
Inherited from
Blockly.FieldDropdown.EDITABLE
enabled_
protected enabled_: boolean;
Can the field value be changed using the editor on an editable block?
Inherited from
Blockly.FieldDropdown.enabled_
fieldGroup_
protected fieldGroup_: SVGGElement | null;
The rendered field's SVG group element.
Inherited from
Blockly.FieldDropdown.fieldGroup_
isDirty_
protected isDirty_: boolean;
Does this block need to be re-rendered?
Inherited from
Blockly.FieldDropdown.isDirty_
isInitialized
isInitialized: boolean;
True once the field’s DOM has been created and it is safe to run ARIA updates in response to value changes.
Inherited from
Blockly.FieldDropdown.isInitialized
maxDisplayLength
maxDisplayLength: number;
Maximum characters of text to display before adding an ellipsis.
Inherited from
Blockly.FieldDropdown.maxDisplayLength
menu_
protected menu_: Menu | null;
The dropdown menu.
Inherited from
Blockly.FieldDropdown.menu_
menuGenerator_?
protected menuGenerator_?: MenuGenerator;
Inherited from
Blockly.FieldDropdown.menuGenerator_
name?
name?: string;
Name of field. Unique within each block. Static labels are usually unnamed.
Inherited from
Blockly.FieldDropdown.name
SERIALIZABLE
SERIALIZABLE: boolean;
Serializable fields are saved by the serializer, non-serializable fields are not. Editable fields should also be serializable.
Inherited from
Blockly.FieldDropdown.SERIALIZABLE
sourceBlock_
protected sourceBlock_: Block | null;
Block this field is attached to. Starts as null, then set in init.
Inherited from
Blockly.FieldDropdown.sourceBlock_
textContent_
protected textContent_: Text | null;
The rendered field's text content element.
Inherited from
Blockly.FieldDropdown.textContent_
textElement_
protected textElement_: SVGTextElement | null;
The rendered field's SVG text element.
Inherited from
Blockly.FieldDropdown.textElement_
validator_
protected validator_: FieldValidator<string> | null;
Validation function called when user edits an editable field.
Inherited from
Blockly.FieldDropdown.validator_
value_
protected value_: string | null;
Inherited from
Blockly.FieldDropdown.value_
visible_
protected visible_: boolean;
Is the field visible, or hidden due to the block being collapsed?
Inherited from
Blockly.FieldDropdown.visible_
ARROW_CHAR
static ARROW_CHAR: string;
Inherited from
Blockly.FieldDropdown.ARROW_CHAR
IMAGE_Y_OFFSET
protected static IMAGE_Y_OFFSET: number;
The y offset from the top of the field to the top of the image, if an image is selected.
Inherited from
Blockly.FieldDropdown.IMAGE_Y_OFFSET
IMAGE_Y_PADDING
protected static IMAGE_Y_PADDING: number;
The total vertical padding above and below an image.
Inherited from
Blockly.FieldDropdown.IMAGE_Y_PADDING
NBSP
readonly static NBSP: " " = "\u00A0";
Non-breaking space.
Inherited from
Blockly.FieldDropdown.NBSP
SEPARATOR
readonly static SEPARATOR: "separator" = "separator";
Magic constant used to represent a separator in a list of dropdown items.
Inherited from
Blockly.FieldDropdown.SEPARATOR
SKIP_SETUP
readonly static SKIP_SETUP: typeof SKIP_SETUP;
A value used to signal when a field's constructor should not set the field's value or run configure_, and should allow a subclass to do that instead.
Inherited from
Blockly.FieldDropdown.SKIP_SETUP
Accessors
size_
Get Signature
get protected size_(): Size;
Gets the size of this field. Because getSize() and updateSize() have side effects, this acts as a shim for subclasses which wish to adjust field bounds when setting/getting the size without triggering unwanted rendering or other side effects. Note that subclasses must override both get and set if either is overridden; the implementation may just call directly through to super, but it must exist per the JS spec.
Returns
Size
Set Signature
set protected size_(newValue): void;
Parameters
| Parameter | Type |
|---|---|
newValue | Size |
Returns
void
Inherited from
Blockly.FieldDropdown.size_
Methods
applyColour()
applyColour(): void;
Updates the dropdown arrow to match the colour/style of the block.
Returns
void
Inherited from
Blockly.FieldDropdown.applyColour
bindEvents_()
protected bindEvents_(): void;
Bind events to the field. Can be overridden by subclasses if they need to do custom input handling.
Returns
void
Inherited from
Blockly.FieldDropdown.bindEvents_
canBeFocused()
canBeFocused(): boolean;
See IFocusableNode.canBeFocused.
Returns
boolean
Inherited from
Blockly.FieldDropdown.canBeFocused
computeAriaLabel()
computeAriaLabel(includeTypeInfo?): string;
Computes a descriptive ARIA label to represent this field with configurable verbosity.
A 'verbose' label includes type information, if available, whereas a non-verbose label only contains the field's value.
Note that this will always return the latest representation of the field's label which may differ from any previously set ARIA label for the field itself. Implementations are largely responsible for ensuring that the field's ARIA label is set correctly at relevant moments in the field's lifecycle (such as when its value changes).
Finally, it is never guaranteed that implementations use the label returned by this method for their actual ARIA label. Some implementations may rely on other contexts to convey information like the field's value. Example: checkboxes represent their checked/non-checked status (i.e. value) through a separate ARIA property.
If the field's value is empty then it will return a localized placeholder indicating that its value is empty. If this method returns an empty string, the output will be ignored when composing the block-level ARIA label. Make sure you want your label hidden from screenreaders before returning an empty string.
Parameters
| Parameter | Type | Description |
|---|---|---|
includeTypeInfo? | boolean | Whether to include the field's type information in the returned label, if available. |
Returns
string
Inherited from
Blockly.FieldDropdown.computeAriaLabel
configure_()
protected configure_(config): void;
Process the configuration map passed to the field.
Parameters
| Parameter | Type | Description |
|---|---|---|
config | FieldConfig | A map of options used to configure the field. See the individual field's documentation for a list of properties this parameter supports. |
Returns
void
Inherited from
Blockly.FieldDropdown.configure_
createBorderRect_()
protected createBorderRect_(): void;
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.
Returns
void
Inherited from
Blockly.FieldDropdown.createBorderRect_
createSVGArrow_()
protected createSVGArrow_(): void;
Create an SVG based arrow.
Returns
void
Inherited from
Blockly.FieldDropdown.createSVGArrow_
createTextArrow_()
protected createTextArrow_(): void;
Create a tspan based arrow.
Returns
void
Inherited from
Blockly.FieldDropdown.createTextArrow_
createTextElement_()
protected createTextElement_(): void;
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. Aria state is hidden; use the aria label for the field and/or containing block to expose content to screen readers. Text content for custom blocks can be set after creation.
Returns
void
Inherited from
Blockly.FieldDropdown.createTextElement_
dispose()
dispose(): void;
Dispose of all DOM objects and events belonging to this editable field.
Returns
void
Inherited from
Blockly.FieldDropdown.dispose
doClassValidation_()
Call Signature
protected doClassValidation_(newValue): string | null | undefined;
Ensure that the input value is a valid language-neutral option.
Parameters
| Parameter | Type | Description |
|---|---|---|
newValue | string | The input value. |
Returns
string | null | undefined
A valid language-neutral option, or null if invalid.
Inherited from
Blockly.FieldDropdown.doClassValidation_
Call Signature
protected doClassValidation_(newValue?): string | null;
Ensure that the input value is a valid language-neutral option.
Parameters
| Parameter | Type | Description |
|---|---|---|
newValue? | string | The input value. |
Returns
string | null
A valid language-neutral option, or null if invalid.
Inherited from
Blockly.FieldDropdown.doClassValidation_
doValueInvalid_()
protected doValueInvalid_(_invalidValue, _fireChangeEvent?): void;
Used to notify the field an invalid value was input. Can be overridden by subclasses, see FieldTextInput. No-op by default.
Parameters
| Parameter | Type | Description |
|---|---|---|
_invalidValue | any | The input value that was determined to be invalid. |
_fireChangeEvent? | boolean | Whether to fire a change event if the value changes. |
Returns
void
Inherited from
Blockly.FieldDropdown.doValueInvalid_
doValueUpdate_()
protected doValueUpdate_(newValue): void;
Update the value of this dropdown field.
Parameters
| Parameter | Type | Description |
|---|---|---|
newValue | string | The value to be saved. The default validator guarantees that this is one of the valid dropdown options. |
Returns
void
Inherited from
Blockly.FieldDropdown.doValueUpdate_
dropdownDispose_()
protected dropdownDispose_(): void;
Disposes of events and DOM-references belonging to the dropdown editor.
Returns
void
Inherited from
Blockly.FieldDropdown.dropdownDispose_
forceRerender()
forceRerender(): void;
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.
Returns
void
Inherited from
Blockly.FieldDropdown.forceRerender
getAbsoluteXY_()
protected getAbsoluteXY_(): 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.
Returns
Coordinate
Object with .x and .y properties.
Inherited from
Blockly.FieldDropdown.getAbsoluteXY_
getAriaTypeName()
getAriaTypeName(): string | null;
Gets an ARIA-friendly label representation of this field's type.
Implementations are responsible for, and encouraged to, return a localized version of the ARIA representation of the field's type.
Returns
string | null
An ARIA representation of the field's type or a default if it is unspecified.
Inherited from
Blockly.FieldDropdown.getAriaTypeName
getAriaValue()
getAriaValue(): string;
Gets an ARIA-friendly label representation of this field's value.
Implementations are responsible for, and encouraged to, return a localized version of the ARIA representation of the field's value.
Returns
string
An ARIA representation of the field's text.
Inherited from
Blockly.FieldDropdown.getAriaValue
getBorderRect()
protected getBorderRect(): SVGRectElement;
Gets the border rectangle element.
Returns
SVGRectElement
The border rectangle element.
Throws
An error if the border rectangle element is not defined.
Inherited from
Blockly.FieldDropdown.getBorderRect
getClickTarget_()
protected getClickTarget_(): Element | null;
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.
Returns
Element | null
Element to bind click handler to.
Inherited from
Blockly.FieldDropdown.getClickTarget_
getConstants()
getConstants(): ConstantProvider | null;
Get the renderer constant provider.
Returns
ConstantProvider | null
The renderer constant provider.
Inherited from
Blockly.FieldDropdown.getConstants
getDisplayText_()
protected getDisplayText_(): string;
Get the text from this field to display on the block. May differ from
getText due to ellipsis, and other formatting.
Returns
string
Text to display.
Inherited from
Blockly.FieldDropdown.getDisplayText_
getFlipRtl()
getFlipRtl(): boolean;
Returns whether or not we should flip the field in RTL.
Returns
boolean
True if we should flip in RTL.
Inherited from
Blockly.FieldDropdown.getFlipRtl
getFocusableElement()
getFocusableElement(): HTMLElement | SVGElement;
See IFocusableNode.getFocusableElement.
Returns
HTMLElement | SVGElement
Inherited from
Blockly.FieldDropdown.getFocusableElement
getFocusableTree()
getFocusableTree(): IFocusableTree;
See IFocusableNode.getFocusableTree.
Returns
IFocusableTree
Inherited from
Blockly.FieldDropdown.getFocusableTree
getOptions()
getOptions(useCache?): MenuOption[];
Return a list of the options for this dropdown.
Parameters
| Parameter | Type | Description |
|---|---|---|
useCache? | boolean | For dynamic options, whether or not to use the cached options or to re-generate them. |
Returns
MenuOption[]
A non-empty array of option tuples: (human-readable text or image, language-neutral name).
Throws
If generated options are incorrectly structured.
Inherited from
Blockly.FieldDropdown.getOptions
getSize()
getSize(): Size;
Returns the height and width of the field.
This should in general be the only place render_ gets called from.
Returns
Size
Height and width.
Inherited from
Blockly.FieldDropdown.getSize
getSourceBlock()
getSourceBlock(): Block | null;
Get the block this field is attached to.
Returns
Block | null
The block containing this field.
Throws
An error if the source block is not defined.
Inherited from
Blockly.FieldDropdown.getSourceBlock
getSvgRoot()
getSvgRoot(): SVGGElement | null;
Gets the group element for this editable field. Used for measuring the size and for positioning.
Returns
SVGGElement | null
The group element.
Inherited from
Blockly.FieldDropdown.getSvgRoot
getText()
getText(): string;
Sealed
Get the text from this field. Override getText_ to provide a different behavior than simply casting the value to a string.
Returns
string
Current text.
Inherited from
Blockly.FieldDropdown.getText
getText_()
protected getText_(): string | null;
Use the getText_ developer hook to override the field's text
representation. Get the selected option text. If the selected option is
an image we return the image alt text. If the selected option is
an HTMLElement, return the title, ariaLabel, or innerText of the
element.
If you use HTMLElement options in Node.js and call this function, ensure that you are supplying an implementation of HTMLElement, such as through jsdom-global.
Returns
string | null
Selected option text.
Inherited from
Blockly.FieldDropdown.getText_
getTextContent()
protected getTextContent(): Text;
Gets the text content.
Returns
Text
The text content.
Throws
An error if the text content is not defined.
Inherited from
Blockly.FieldDropdown.getTextContent
getTextElement()
protected getTextElement(): SVGTextElement;
Gets the text element.
Returns
SVGTextElement
The text element.
Throws
An error if the text element is not defined.
Inherited from
Blockly.FieldDropdown.getTextElement
getTooltip()
getTooltip(): string;
Returns the tooltip text for this field.
Returns
string
The tooltip text for this field.
Inherited from
Blockly.FieldDropdown.getTooltip
getValidator()
getValidator(): FieldValidator<string> | null;
Gets the validation function for editable fields, or null if not set.
Returns
FieldValidator<string> | null
Validation function, or null.
Inherited from
Blockly.FieldDropdown.getValidator
getValue()
getValue(): string | null;
Get the current value of the field.
Returns
string | null
Current value.
Inherited from
Blockly.FieldDropdown.getValue
initModel()
initModel(): void;
Initializes the model of the field after it has been installed on a block. No-op by default.
Returns
void
Inherited from
Blockly.FieldDropdown.initModel
initView()
initView(): void;
Create the block UI for this dropdown.
Returns
void
Inherited from
Blockly.FieldDropdown.initView
isClickable()
isClickable(): boolean;
Check whether this field defines the showEditor_ function.
Returns
boolean
Whether this field is clickable.
Inherited from
Blockly.FieldDropdown.isClickable
isClickableInFlyout()
isClickableInFlyout(autoClosingFlyout): boolean;
Check whether the field should be clickable while the block is in a flyout.
The default is that fields are clickable in always-open flyouts such as the
simple toolbox, but not in autoclosing flyouts such as the category toolbox.
Subclasses may override this function to change this behavior. Note that
isClickable must also return true for this to have any effect.
Parameters
| Parameter | Type | Description |
|---|---|---|
autoClosingFlyout | boolean | true if the containing flyout is an auto-closing one. |
Returns
boolean
Whether the field should be clickable while the block is in a flyout.
Inherited from
Blockly.FieldDropdown.isClickableInFlyout
isCurrentlyEditable()
isCurrentlyEditable(): 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.
Returns
boolean
Whether this field is currently enabled, editable and on an editable block.
Inherited from
Blockly.FieldDropdown.isCurrentlyEditable
isEnabled()
isEnabled(): boolean;
Check whether this field's value can be changed using the editor when the source block is editable.
Returns
boolean
Whether this field is enabled.
Inherited from
Blockly.FieldDropdown.isEnabled
isFullBlockField()
isFullBlockField(): boolean;
This is hacky way of determining if a dropdown field is a full-block field or not. The constants that control the border rect are the same ones that determine how we render full-block dropdown fields. It's a full-block field if it doesn't have the border rect (and it's a simple reporter block).
Returns
boolean
true if this field should be treated as a full-block field
Inherited from
Blockly.FieldDropdown.isFullBlockField
isOptionListDynamic()
isOptionListDynamic(): boolean;
Returns
boolean
True if the option list is generated by a function. Otherwise false.
Inherited from
Blockly.FieldDropdown.isOptionListDynamic
isSerializable()
isSerializable(): boolean;
Check whether this field should be serialized by the XML renderer. Handles the logic for backwards compatibility and incongruous states.
Returns
boolean
Whether this field should be serialized or not.
Inherited from
Blockly.FieldDropdown.isSerializable
isVisible()
isVisible(): boolean;
Gets whether this editable field is visible or not.
Returns
boolean
True if visible.
Inherited from
Blockly.FieldDropdown.isVisible
loadLegacyState()
loadLegacyState(callingClass, state): boolean;
Loads the given state using either the old XML hooks, if they should be used. Returns true to indicate loading has been handled, false otherwise.
Parameters
| Parameter | Type | Description |
|---|---|---|
callingClass | FieldProto | The class calling this method. Used to see if this has overridden any relevant hooks. |
state | any | The state to apply to the field. |
Returns
boolean
Whether the state was applied or not.
Inherited from
Blockly.FieldDropdown.loadLegacyState
onItemSelected_()
protected onItemSelected_(menu, menuItem): void;
Handle the selection of an item in the dropdown menu.
Parameters
| Parameter | Type | Description |
|---|---|---|
menu | Menu | The Menu component clicked. |
menuItem | MenuItem | The MenuItem selected within menu. |
Returns
void
Inherited from
Blockly.FieldDropdown.onItemSelected_
onLocationChange()
onLocationChange(_): void;
Notifies the field that it has changed locations.
Parameters
| Parameter | Type | Description |
|---|---|---|
_ | Coordinate | The location of this field's block's top-start corner in workspace coordinates. |
Returns
void
Inherited from
Blockly.FieldDropdown.onLocationChange
onMouseDown_()
protected onMouseDown_(e): void;
Handle a pointerdown event on a field.
Parameters
| Parameter | Type | Description |
|---|---|---|
e | PointerEvent | Pointer down event. |
Returns
void
Inherited from
Blockly.FieldDropdown.onMouseDown_
onNodeBlur()
onNodeBlur(): void;
See IFocusableNode.onNodeBlur.
Returns
void
Inherited from
Blockly.FieldDropdown.onNodeBlur
onNodeFocus()
onNodeFocus(): void;
See IFocusableNode.onNodeFocus.
Returns
void
Inherited from
Blockly.FieldDropdown.onNodeFocus
onShortcut()
onShortcut(_shortcut): boolean;
Handles the given keyboard shortcut.
Parameters
| Parameter | Type | Description |
|---|---|---|
_shortcut | KeyboardShortcut | The shortcut to be handled. |
Returns
boolean
True if the shortcut has been handled, false otherwise.
Inherited from
Blockly.FieldDropdown.onShortcut
performAction()
performAction(): void;
Handles the user acting on this field via keyboard navigation. Shows and focuses the field editor.
Returns
void
Inherited from
Blockly.FieldDropdown.performAction
positionBorderRect_()
protected positionBorderRect_(): void;
Position a field's border rect after a size change.
Returns
void
Inherited from
Blockly.FieldDropdown.positionBorderRect_
positionTextElement_()
protected positionTextElement_(xOffset, contentWidth): void;
Position a field's text element after a size change. This handles both LTR and RTL positioning.
Parameters
| Parameter | Type | Description |
|---|---|---|
xOffset | number | x offset to use when positioning the text element. |
contentWidth | number | The content width. |
Returns
void
Inherited from
Blockly.FieldDropdown.positionTextElement_
recomputeAriaContext()
recomputeAriaContext(): boolean;
Sets additional aria state.
Returns
boolean
Inherited from
Blockly.FieldDropdown.recomputeAriaContext
referencesVariables()
referencesVariables(): boolean;
Whether this field references any Blockly variables. If true it may need to be handled differently during serialization and deserialization, and this field's value must correspond to the ID of an existing variable. Subclasses may override this.
Returns
boolean
True if this field has any variable references.
Inherited from
Blockly.FieldDropdown.referencesVariables
refreshVariableName()
refreshVariableName(): void;
Refresh the variable name referenced by this field if this field references variables.
Returns
void
Inherited from
Blockly.FieldDropdown.refreshVariableName
render_()
protected render_(): void;
Draws the border with the correct width.
Returns
void
Inherited from
Blockly.FieldDropdown.render_
repositionForWindowResize()
repositionForWindowResize(): boolean;
A developer hook to reposition the WidgetDiv during a window resize. You need to define this hook if your field has a WidgetDiv that needs to reposition itself when the window is resized. For example, text input fields define this hook so that the input WidgetDiv can reposition itself on a window resize event. This is especially important when modal inputs have been disabled, as Android devices will fire a window resize event when the soft keyboard opens.
If you want the WidgetDiv to hide itself instead of repositioning, return false. This is the default behavior.
DropdownDivs already handle their own positioning logic, so you do not need to override this function if your field only has a DropdownDiv.
Returns
boolean
True if the field should be repositioned, false if the WidgetDiv should hide itself instead.
Inherited from
Blockly.FieldDropdown.repositionForWindowResize
saveLegacyState()
protected saveLegacyState(callingClass): string | null;
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.
Parameters
| Parameter | Type | Description |
|---|---|---|
callingClass | FieldProto | The class calling this method. Used to see if this has overridden any relevant hooks. |
Returns
string | null
The stringified version of the XML state, or null.
Inherited from
Blockly.FieldDropdown.saveLegacyState
saveState()
saveState(_doFullSerialization?): any;
Saves this fields value as something which can be serialized to JSON. Should only be called by the serialization system.
Parameters
| Parameter | Type | Description |
|---|---|---|
_doFullSerialization? | boolean | 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. See the field serialization docs for more information. |
Returns
any
JSON serializable state.
Inherited from
Blockly.FieldDropdown.saveState
setAriaTypeName()
setAriaTypeName(ariaTypeName): void;
Sets the ARIA-friendly label representation of this field's type.
Implementations are responsible for, and encouraged to, set a localized
version of the ARIA representation of the field's type. To that end, the
provided value may contain message references of the form %{BKY_...}
(e.g. %{BKY_MY_FIELD_ARIA_TYPE}), which are replaced with the
corresponding Blockly.Msg value.
Parameters
| Parameter | Type | Description |
|---|---|---|
ariaTypeName | string | An ARIA representation of the field's type. |
Returns
void
Inherited from
Blockly.FieldDropdown.setAriaTypeName
setEnabled()
setEnabled(enabled): void;
Set whether this field's value can be changed using the editor when the source block is editable.
Parameters
| Parameter | Type | Description |
|---|---|---|
enabled | boolean | True if enabled. |
Returns
void
Inherited from
Blockly.FieldDropdown.setEnabled
setOptions()
setOptions(menuGenerator): void;
Update the options on this dropdown. This will reset the selected item to the first item in the list.
Parameters
| Parameter | Type | Description |
|---|---|---|
menuGenerator | MenuGenerator | The array of options or a generator function. |
Returns
void
Inherited from
Blockly.FieldDropdown.setOptions
setSourceBlock()
setSourceBlock(block): void;
Defined in: plugins/field-dependent-dropdown/src/field_dependent_dropdown.ts:186
Attach this field to a block.
Parameters
| Parameter | Type | Description |
|---|---|---|
block | Block | The block containing this field. |
Returns
void
Overrides
Blockly.FieldDropdown.setSourceBlock
setTooltip()
setTooltip(newTip): void;
Sets the tooltip for this field.
Parameters
| Parameter | Type | Description |
|---|---|---|
newTip | TipInfo | null | 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. |
Returns
void
Inherited from
Blockly.FieldDropdown.setTooltip
setValidator()
setValidator(handler): void;
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.
Parameters
| Parameter | Type | Description |
|---|---|---|
handler | FieldValidator<string> | The validator function or null to clear a previous validator. |
Returns
void
Inherited from
Blockly.FieldDropdown.setValidator
setValue()
setValue(newValue, fireChangeEvent?): void;
Sealed
Used to change the value of the field. Handles validation and events. Subclasses should override doClassValidation_ and doValueUpdate_ rather than this method.
Parameters
| Parameter | Type | Description |
|---|---|---|
newValue | any | New value. |
fireChangeEvent? | boolean | Whether to fire a change event. Defaults to true. Should usually be true unless the change will be reported some other way, e.g. an intermediate field change event. |
Returns
void
Inherited from
Blockly.FieldDropdown.setValue
shouldAddBorderRect_()
protected shouldAddBorderRect_(): boolean;
Whether or not the dropdown should add a border rect.
Returns
boolean
True if the dropdown field should add a border rect.
Inherited from
Blockly.FieldDropdown.shouldAddBorderRect_
showEditor_()
protected showEditor_(e?): void;
Create a dropdown menu under the text.
Parameters
| Parameter | Type | Description |
|---|---|---|
e? | MouseEvent | Optional mouse event that triggered the field to open, or undefined if triggered programmatically. |
Returns
void
Inherited from
Blockly.FieldDropdown.showEditor_
toXml()
toXml(fieldElement): Element;
Serializes this field's value to XML. Should only be called by Blockly.Xml.
Parameters
| Parameter | Type | Description |
|---|---|---|
fieldElement | Element | The element to populate with info about the field's state. |
Returns
Element
The element containing info about the field's state.
Inherited from
Blockly.FieldDropdown.toXml
trimOptions()
protected trimOptions(options): object;
Factor out common words in statically defined options. Create prefix and/or suffix labels.
Parameters
| Parameter | Type |
|---|---|
options | MenuOption[] |
Returns
object
options
options: MenuOption[];
prefix?
prefix?: string;
suffix?
suffix?: string;
Inherited from
Blockly.FieldDropdown.trimOptions
updateEditable()
updateEditable(): void;
Add or remove the UI indicating if this field is editable or not.
Returns
void
Inherited from
Blockly.FieldDropdown.updateEditable
updateSize_()
protected updateSize_(margin?): void;
Updates the size of the field based on the text.
Parameters
| Parameter | Type | Description |
|---|---|---|
margin? | number | margin to use when positioning the text element. |
Returns
void
Inherited from
Blockly.FieldDropdown.updateSize_
validateOptions()
protected validateOptions(options): void;
Validates the data structure to be processed as an options list.
Parameters
| Parameter | Type | Description |
|---|---|---|
options | MenuOption[] | The proposed dropdown options. |
Returns
void
Throws
If proposed options are incorrectly structured.
Inherited from
Blockly.FieldDropdown.validateOptions
fromJson()
static fromJson(options): FieldDependentDropdown;
Defined in: plugins/field-dependent-dropdown/src/field_dependent_dropdown.ts:169
Constructs a FieldDependentDropdown from a JSON arg object.
Parameters
| Parameter | Type | Description |
|---|---|---|
options | FieldDependentDropdownFromJsonConfig | A JSON object providing "parentName" and "optionMapping". |
Returns
FieldDependentDropdown
The new field instance.
Overrides
Blockly.FieldDropdown.fromJson