diff --git a/blocks_vertical/procedures.js b/blocks_vertical/procedures.js index 1164ce76b7..d5fabec337 100644 --- a/blocks_vertical/procedures.js +++ b/blocks_vertical/procedures.js @@ -623,13 +623,15 @@ Blockly.ScratchBlocks.ProcedureUtils.updateDeclarationProcCode_ = function() { this.procCode_ += input.fieldRow[0].getValue(); } else if (input.type == Blockly.INPUT_VALUE) { // Inspect the argument editor. - var target = input.connection.targetBlock(); - this.displayNames_.push(target.getFieldValue('TEXT')); - this.argumentIds_.push(input.name); - if (target.type == 'argument_editor_boolean') { - this.procCode_ += '%b'; - } else { - this.procCode_ += '%s'; + var target = input.connection ? input.connection.targetBlock() : null; + if (target) { + this.displayNames_.push(target.getFieldValue('TEXT')); + this.argumentIds_.push(input.name); + if (target.type == 'argument_editor_boolean') { + this.procCode_ += '%b'; + } else { + this.procCode_ += '%s'; + } } } else { throw new Error( @@ -649,8 +651,10 @@ Blockly.ScratchBlocks.ProcedureUtils.focusLastEditor_ = function() { newInput.fieldRow[0].showEditor_(); } else if (newInput.type == Blockly.INPUT_VALUE) { // Inspect the argument editor. - var target = newInput.connection.targetBlock(); - target.getField('TEXT').showEditor_(); + var target = newInput.connection ? newInput.connection.targetBlock() : null; + if (target) { + target.getField('TEXT').showEditor_(); + } } } }; @@ -737,7 +741,7 @@ Blockly.ScratchBlocks.ProcedureUtils.removeFieldCallback = function(field) { var input = this.inputList[n]; if (input.connection) { var target = input.connection.targetBlock(); - if (target.getField(field.name) == field) { + if (target && target.getField(field.name) == field) { inputNameToRemove = input.name; } } else { diff --git a/core/field_customInput.js b/core/field_customInput.js index acf0a49a7c..638034e3f8 100644 --- a/core/field_customInput.js +++ b/core/field_customInput.js @@ -159,6 +159,18 @@ Blockly.FieldCustom.prototype.getValue = function() { return this.value_; }; +/** + * Get the text from this field for display and XML serialization. + * Return empty string since the actual code is stored in value_ and + * should not be serialized as display text. + * @return {string} Empty string for display. + */ +Blockly.FieldCustom.prototype.getText = function() { + // Return empty string to avoid serializing code with special characters + // The actual value is handled separately via getValue/setValue + return ''; +}; + /** * do whatever the user desires on-edit * @private