Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions core/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -1630,6 +1630,8 @@ Blockly.Block.prototype.interpolate_ = function(message, args, lastDummyAlign) {
input = this.appendDummyInput(element['name']);
break;
default:
// This should handle all field JSON parsing, including
// options that can be applied to any field type.
field = Blockly.Field.fromJson(element);

// Unknown field.
Expand Down
8 changes: 7 additions & 1 deletion core/field.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,13 @@ Blockly.Field.register = function(type, fieldClass) {
Blockly.Field.fromJson = function(options) {
var fieldClass = Blockly.Field.TYPE_MAP_[options['type']];
if (fieldClass) {
return fieldClass.fromJson(options);
var field = fieldClass.fromJson(options);
if (options['tooltip'] !== undefined) {
var rawValue = options['tooltip'];
var localizedText = Blockly.utils.replaceMessageReferences(rawValue);
field.setTooltip(localizedText);
}
return field;
}
return null;
};
Expand Down
22 changes: 22 additions & 0 deletions tests/blocks/test_blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,28 @@ Blockly.defineBlocksWithJsonArray([ // BEGIN JSON EXTRACT
"nextStatement": null,
"style": "math_blocks",
},
{
"type": "test_basic_tooltips",
"message0": "%1 %2 %3",
"args0": [
{
"type": "field_label",
"name": "NAME",
"text": "field tooltip",
"tooltip": "This is a JSON tooltip for the *field*."
},
{
"type": "input_dummy"
},
{
"type": "field_label",
"name": "NAME",
"text": "block tooltip"
}
],
"tooltip": "This is a JSON tooltip for the *block*.",
"style": "math_blocks"
},
{
"type": "test_dropdowns_long",
"message0": "long: %1",
Expand Down
1 change: 1 addition & 0 deletions tests/playground.html
Original file line number Diff line number Diff line change
Expand Up @@ -1207,6 +1207,7 @@ <h1>Blockly Playground</h1>
<block type="test_basic_value_to_stack"></block>
<block type="test_basic_value_to_statement"></block>
<block type="test_basic_limit_instances"></block>
<block type="test_basic_tooltips"></block>
</category>
<category name="Drag">
<label text="Drag each to the workspace"></label>
Expand Down