Campi dell'etichetta
Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
Un campo di etichetta memorizza una stringa come value
e una stringa come text
. value
e text
di un campo dell'etichetta sono sempre uguali.
Campo dell'etichetta

Campo dell'etichetta nel blocco compresso

Creazione
JSON
{
"type": "example_label",
"message0": "a label %1 and another label",
"args0": [
{
"type": "input_dummy"
}
]
}
Qualsiasi testo del messaggio tra gli argomenti di interpolazione diventa stringhe di etichetta.
In alternativa, le etichette possono essere interpolate esplicitamente come oggetto o come testo. In genere, questa opzione non è consigliata perché rende più difficile la traduzione.
{
"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');
}
};
La funzione appendField accetta sia oggetti FieldLabel
sia, più comunemente, stringhe per creare etichette.
Il campo dell'etichetta accetta un valore facoltativo e una stringa di classe CSS facoltativa.
Per entrambi il valore predefinito è una stringa vuota.
Serializzazione
I campi delle etichette non sono serializzabili.
Se vuoi che l'etichetta venga serializzata perché viene modificata tramite programmazione, consulta il campo Etichetta serializzabile.
Strumenti di convalida
I campi delle etichette non supportano i convalidatori perché non sono modificabili.
Salvo quando diversamente specificato, i contenuti di questa pagina sono concessi in base alla licenza Creative Commons Attribution 4.0, mentre gli esempi di codice sono concessi in base alla licenza Apache 2.0. Per ulteriori dettagli, consulta le norme del sito di Google Developers. Java è un marchio registrato di Oracle e/o delle sue consociate.
Ultimo aggiornamento 2025-07-25 UTC.
[null,null,["Ultimo aggiornamento 2025-07-25 UTC."],[[["\u003cp\u003eA label field displays text on a block and stores the same string as both its \u003ccode\u003evalue\u003c/code\u003e and \u003ccode\u003etext\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eLabel fields can be created using JSON by specifying message strings or by explicitly interpolating labels, though the latter is discouraged for translation reasons.\u003c/p\u003e\n"],["\u003cp\u003eIn JavaScript, label fields are created using \u003ccode\u003eBlockly.FieldLabel\u003c/code\u003e and appended to block inputs using \u003ccode\u003eappendField\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eWhile not serializable by default, a separate "Serializable Label" field exists for cases requiring programmatic changes and serialization.\u003c/p\u003e\n"],["\u003cp\u003eLabel fields do not support validators due to their non-editable nature.\u003c/p\u003e\n"]]],[],null,["# Label fields\n\nA label field stores a string as its `value` and a string as its `text`. The\n`value` and `text` of a label field are always the same.\n\n#### Label field\n\n#### Label field on collapsed block\n\nCreation\n--------\n\n### JSON\n\n {\n \"type\": \"example_label\",\n \"message0\": \"a label %1 and another label\",\n \"args0\": [\n {\n \"type\": \"input_dummy\"\n }\n ]\n }\n\nAny message text between interpolation arguments becomes label strings.\nAlternatively, labels may be interpolated explicitly, either as an object or\nas text. This is generally discouraged as it makes translation more\ndifficult. \n\n {\n \"type\": \"example_label\",\n \"message0\": \"%1 %2 %3\",\n \"args0\": [\n {\n \"type\": \"field_label\",\n \"text\": \"a label\"\n },\n {\n \"type\": \"input_dummy\"\n },\n \"and another label\"\n ]\n }\n\n### JavaScript\n\n Blockly.Blocks['example_label'] = {\n init: function() {\n this.appendDummyInput()\n .appendField(new Blockly.FieldLabel('a label'));\n this.appendDummyInput()\n .appendField('and another label');\n }\n };\n\nThe [appendField](/blockly/reference/js/Blockly.Input#appendField)\nfunction accepts both `FieldLabel` objects and, more commonly, strings to create\nlabels.\n\nThe label field takes in an optional value, and an optional css class string.\nBoth default to an empty string.\n\nSerialization\n-------------\n\nLabel fields are not serializable.\n\nIf you would like your label to be serialized, because it is being changed\nprogrammatically, see the [Serializable Label](/blockly/guides/create-custom-blocks/fields/built-in-fields/label-serializable)\nfield.\n\nValidators\n----------\n\nLabel fields do not support validators, because they are not editable."]]