From 4a0d5f5df083679e6d4a79225a31639cc654bdbf Mon Sep 17 00:00:00 2001 From: Beka Westberg Date: Fri, 14 Jun 2019 11:50:42 -0700 Subject: [PATCH 1/2] Added sending the bad value to doValueInvalid. --- core/field.js | 15 ++++++++------- core/field_date.js | 11 ----------- core/field_textinput.js | 5 ++++- 3 files changed, 12 insertions(+), 19 deletions(-) diff --git a/core/field.js b/core/field.js index 7c50b46a6..3ad8d3cfb 100644 --- a/core/field.js +++ b/core/field.js @@ -779,16 +779,16 @@ Blockly.Field.prototype.setValue = function(newValue) { */ Blockly.Field.prototype.processValidation_ = function(newValue, validatedValue) { - if (validatedValue !== undefined) { - newValue = validatedValue; - } - if (newValue === null) { - this.doValueInvalid_(); + if (validatedValue === null) { + this.doValueInvalid_(newValue); if (this.isDirty_) { this.forceRerender(); } return Error(); } + if (validatedValue !== undefined) { + newValue = validatedValue; + } return newValue; }; @@ -827,12 +827,13 @@ Blockly.Field.prototype.doValueUpdate_ = function(newValue) { }; /** - * Used to notify the field an invalid value was input. Can be overiden by + * Used to notify the field an invalid value was input. Can be overidden by * subclasses, see FieldTextInput. * No-op by default. + * @param {*} _newValue The input value that was determined to be invalid. * @protected */ -Blockly.Field.prototype.doValueInvalid_ = function() { +Blockly.Field.prototype.doValueInvalid_ = function(_newValue) { // NOP }; diff --git a/core/field_date.js b/core/field_date.js index 20290fa68..1586de38a 100644 --- a/core/field_date.js +++ b/core/field_date.js @@ -116,17 +116,6 @@ Blockly.FieldDate.prototype.doClassValidation_ = function(newValue) { return newValue; }; -/** - * Called when the given value is invalid. If the picker is shown, set - * isDirty to true so that it gets reset to the previous selection. - * @protected - */ -Blockly.FieldDate.prototype.doValueInvalid_ = function() { - if (this.picker_) { - this.isDirty_ = true; - } -}; - /** * Render the field. If the picker is shown make sure it has the current * date selected. diff --git a/core/field_textinput.js b/core/field_textinput.js index a79d55e03..495d7b447 100644 --- a/core/field_textinput.js +++ b/core/field_textinput.js @@ -115,9 +115,12 @@ Blockly.FieldTextInput.prototype.doClassValidation_ = function(newValue) { * Called by setValue if the text input is not valid. If the field is * currently being edited it reverts value of the field to the previous * value while allowing the display text to be handled by the htmlInput_. + * @param {*} _newValue The input value that was determined to be invalid. + * This is not used by the text input because its display value is stored on + * the htmlInput_. * @protected */ -Blockly.FieldTextInput.prototype.doValueInvalid_ = function() { +Blockly.FieldTextInput.prototype.doValueInvalid_ = function(_newValue) { if (this.isBeingEdited_) { this.isTextValid_ = false; var oldValue = this.value_; From 3227223c823a2077a261dea5955063fae274fa0e Mon Sep 17 00:00:00 2001 From: Beka Westberg Date: Mon, 24 Jun 2019 14:58:33 -0700 Subject: [PATCH 2/2] Renamed _newValue param to _invalidValue. --- core/field.js | 4 ++-- core/field_textinput.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/core/field.js b/core/field.js index 3ad8d3cfb..64616d3cb 100644 --- a/core/field.js +++ b/core/field.js @@ -830,10 +830,10 @@ Blockly.Field.prototype.doValueUpdate_ = function(newValue) { * Used to notify the field an invalid value was input. Can be overidden by * subclasses, see FieldTextInput. * No-op by default. - * @param {*} _newValue The input value that was determined to be invalid. + * @param {*} _invalidValue The input value that was determined to be invalid. * @protected */ -Blockly.Field.prototype.doValueInvalid_ = function(_newValue) { +Blockly.Field.prototype.doValueInvalid_ = function(_invalidValue) { // NOP }; diff --git a/core/field_textinput.js b/core/field_textinput.js index 495d7b447..bb68cee10 100644 --- a/core/field_textinput.js +++ b/core/field_textinput.js @@ -115,12 +115,12 @@ Blockly.FieldTextInput.prototype.doClassValidation_ = function(newValue) { * Called by setValue if the text input is not valid. If the field is * currently being edited it reverts value of the field to the previous * value while allowing the display text to be handled by the htmlInput_. - * @param {*} _newValue The input value that was determined to be invalid. + * @param {*} _invalidValue The input value that was determined to be invalid. * This is not used by the text input because its display value is stored on * the htmlInput_. * @protected */ -Blockly.FieldTextInput.prototype.doValueInvalid_ = function(_newValue) { +Blockly.FieldTextInput.prototype.doValueInvalid_ = function(_invalidValue) { if (this.isBeingEdited_) { this.isTextValid_ = false; var oldValue = this.value_;