Add opt quiet to remove field (#3968)

* Add opt quiet to remove field
This commit is contained in:
alschmiedt
2020-06-12 14:18:28 -07:00
committed by GitHub
parent 9ec8305889
commit 4335bb6452
2 changed files with 12 additions and 5 deletions

View File

@@ -1806,7 +1806,7 @@ Blockly.Block.prototype.moveNumberedInputBefore = function(
/**
* Remove an input from this block.
* @param {string} name The name of the input.
* @param {boolean=} opt_quiet True to prevent error if input is not present.
* @param {boolean=} opt_quiet True to prevent an error if input is not present.
* @return {boolean} True if operation succeeds, false if input is not present and opt_quiet is true
* @throws {Error} if the input is not present and opt_quiet is not true.
*/

View File

@@ -134,9 +134,12 @@ Blockly.Input.prototype.insertFieldAt = function(index, field, opt_name) {
/**
* Remove a field from this input.
* @param {string} name The name of the field.
* @throws {Error} if the field is not present.
* @param {boolean=} opt_quiet True to prevent an error if field is not present.
* @return {boolean} True if operation succeeds, false if field is not present
* and opt_quiet is true.
* @throws {Error} if the field is not present and opt_quiet is false.
*/
Blockly.Input.prototype.removeField = function(name) {
Blockly.Input.prototype.removeField = function(name, opt_quiet) {
for (var i = 0, field; (field = this.fieldRow[i]); i++) {
if (field.name === name) {
field.dispose();
@@ -147,10 +150,14 @@ Blockly.Input.prototype.removeField = function(name) {
// Removing a field will cause the block to change shape.
this.sourceBlock_.bumpNeighbours();
}
return;
return true;
}
}
throw Error('Field "%s" not found.', name);
if (opt_quiet) {
return false;
} else {
throw Error('Field "' + name + '" not found.');
}
};
/**