From a8a8c320d515e57d37f6e2b166b04dbdb1fc92cd Mon Sep 17 00:00:00 2001 From: Beka Westberg Date: Wed, 18 Sep 2019 16:30:17 -0700 Subject: [PATCH] Changed multiline field to use new configuration (#3044) * Changed multilineinput field to new configuration. --- core/field_multilineinput.js | 20 ++++++++++---------- core/field_textinput.js | 3 +-- tests/blocks/test_blocks.js | 13 +++++++++++++ tests/playground.html | 1 + 4 files changed, 25 insertions(+), 12 deletions(-) diff --git a/core/field_multilineinput.js b/core/field_multilineinput.js index d7c2f7caa..93dc6d6c0 100644 --- a/core/field_multilineinput.js +++ b/core/field_multilineinput.js @@ -46,15 +46,20 @@ goog.require('Blockly.utils.userAgent'); * to validate any constraints on what the user entered. Takes the new * text as an argument and returns either the accepted text, a replacement * text, or null to abort the change. + * @param {Object=} opt_config A map of options used to configure the field. + * See the [field creation documentation]{@link https://developers.google.com/blockly/guides/create-custom-blocks/fields/built-in-fields/text-input#creation} + * for a list of properties this parameter supports. * @extends {Blockly.FieldTextInput} * @constructor */ -Blockly.FieldMultilineInput = function(opt_value, opt_validator) { - if (opt_value === null) { +Blockly.FieldMultilineInput = function(opt_value, opt_validator, opt_config) { + // TODO: Once this field is documented the opt_config link should point to its + // creation documentation, rather than the text input field's. + if (opt_value == null) { opt_value = ''; } Blockly.FieldMultilineInput.superClass_.constructor.call(this, - opt_value, opt_validator); + opt_value, opt_validator, opt_config); }; Blockly.utils.object.inherits(Blockly.FieldMultilineInput, Blockly.FieldTextInput); @@ -70,19 +75,14 @@ Blockly.FieldMultilineInput.LINE_HEIGHT = 20; /** * Construct a FieldMultilineInput from a JSON arg object, * dereferencing any string table references. - * @param {!Object} options A JSON object with options (text, class, and - * spellcheck). + * @param {!Object} options A JSON object with options (text, and spellcheck). * @return {!Blockly.FieldMultilineInput} The new field instance. * @package * @nocollapse */ Blockly.FieldMultilineInput.fromJson = function(options) { var text = Blockly.utils.replaceMessageReferences(options['text']); - var field = new Blockly.FieldMultilineInput(text); - if (typeof options['spellcheck'] === 'boolean') { - field.setSpellcheck(options['spellcheck']); - } - return field; + return new Blockly.FieldMultilineInput(text, undefined, options); }; /** diff --git a/core/field_textinput.js b/core/field_textinput.js index 94fbb46f3..321570a4b 100644 --- a/core/field_textinput.js +++ b/core/field_textinput.js @@ -73,8 +73,7 @@ Blockly.utils.object.inherits(Blockly.FieldTextInput, Blockly.Field); /** * Construct a FieldTextInput from a JSON arg object, * dereferencing any string table references. - * @param {!Object} options A JSON object with options (text, class, and - * spellcheck). + * @param {!Object} options A JSON object with options (text, and spellcheck). * @return {!Blockly.FieldTextInput} The new field instance. * @package * @nocollapse diff --git a/tests/blocks/test_blocks.js b/tests/blocks/test_blocks.js index 22a1a32c1..e84cbd6e9 100644 --- a/tests/blocks/test_blocks.js +++ b/tests/blocks/test_blocks.js @@ -272,6 +272,19 @@ Blockly.defineBlocksWithJsonArray([ // BEGIN JSON EXTRACT "tooltip": "", "helpUrl": "" }, + { + "type": "test_fields_multilinetext", + "message0": "code %1", + "args0": [ + { + "type": "field_multilinetext", + "name": "CODE", + "text": "default1\ndefault2" + } + ], + "style": "math_blocks", + "tooltip": "test tooltip" + }, { "type": "test_fields_checkbox", "message0": "checkbox %1", diff --git a/tests/playground.html b/tests/playground.html index 28a18c58f..04835dba7 100644 --- a/tests/playground.html +++ b/tests/playground.html @@ -1435,6 +1435,7 @@ var spaghettiXml = [ +