Added handling of dynamic functions passed to opt_config.

This commit is contained in:
Beka Westberg
2019-08-16 15:29:21 -07:00
parent 9fde484a87
commit 4f411d2859
2 changed files with 14 additions and 1 deletions

View File

@@ -58,7 +58,11 @@ Blockly.Field = function(value, opt_validator, opt_config) {
this.size_ = new Blockly.utils.Size(0, 0);
if (opt_config) {
var tooltip = Blockly.utils.replaceMessageReferences(opt_config['tooltip']);
var tooltip = opt_config['tooltip'];
if (typeof tooltip == 'string') {
tooltip = Blockly.utils.replaceMessageReferences(
opt_config['tooltip']);
}
tooltip && this.setTooltip(tooltip);
// TODO: Possibly eventually add configurations like cursor and css class.

View File

@@ -359,6 +359,15 @@ suite('Abstract Fields', function() {
});
chai.assert.equal(field.tooltip_, 'test tooltip');
});
test('JS Constructor - Dynamic', function() {
var returnTooltip = function() {
return 'dynamic tooltip text';
};
var field = new Blockly.Field('value', null, {
tooltip: returnTooltip
});
chai.assert.equal(field.tooltip_, returnTooltip);
});
test('JSON Definition', function() {
var field = CustomField.fromJson({
tooltip: "test tooltip"