Serializable label fields
Serializable labels work exactly the same as normal labels except they also serialize to XML. They should only be used if you are editing the content of a label programmatically, and wish it to serialize to XML.
Serializable label field
Serializable label field on a collapsed block
Creation
- JSON
- JavaScript
{
"type": "example_serializable_label",
"message0": "%1",
"args0": [
{
"type": "field_label_serializable",
"name": "FIELDNAME",
"text": "a serializable label"
}
]
}
Blockly.Blocks['example_serializable_label'] = {
init: function() {
this.appendDummyInput()
.appendField(new Blockly.FieldLabelSerializable("a serializable label"), "FIELDNAME");
}
};
The serializable label field takes in an optional value, and an optional css class string. Both default to an empty string.
Serialization
- JSON
- XML
The JSON for a serializable label field looks like so:
{
"fields": {
"FIELDNAME": text
}
}
Where FIELDNAME is a string referencing a serializable label field, and
the value is the value to apply to the field. The value
follows the same rules as the constructor value.
The XML for a serializable label field looks like so:
<field name="FIELDNAME">text</field>
The field node's name attribute contains a string referencing a serializable
label field, and the node's inner text is the value to apply to the field.
Accessibility
Serializable label fields cannot be focused directly with keyboard navigation.
The on-block display has the ARIA role generic. There is no editor display.
The label's text is used to construct the parent block's ARIA label.
Validators
Serializable label fields do not support validators, because they are not editable by a user.