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

{
  "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"
  ]
}

JavaScript

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.

Validators

Label fields do not support validators, because they are not editable.