Label fields
A label field stores a string as its value and a string as its text. The
value and text of a label field are always the same.
Label field
Label field on collapsed block
Creation
- JSON
- JavaScript
{
"type": "example_label",
"message0": "a label %1 and another label",
"args0": [
{
"type": "input_dummy"
}
]
}
Any message text between interpolation arguments becomes label strings. Alternatively, labels may be interpolated explicitly, either as an object or as text. This is generally discouraged as it makes translation more difficult.
{
"type": "example_label",
"message0": "%1 %2 %3",
"args0": [
{
"type": "field_label",
"text": "a label"
},
{
"type": "input_dummy"
},
"and another label"
]
}
Blockly.Blocks['example_label'] = {
init: function() {
this.appendDummyInput()
.appendField(new Blockly.FieldLabel('a label'));
this.appendDummyInput()
.appendField('and another label');
}
};
The appendField
function accepts both FieldLabel objects and, more commonly, strings to create
labels.
The label field takes in an optional value, and an optional css class string. Both default to an empty string.
Serialization
Label fields are not serializable.
If you would like your label to be serialized, because it is being changed programmatically, see the Serializable Label field.
Accessibility
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
Label fields do not support validators, because they are not editable.