diff --git a/core/field_input.ts b/core/field_input.ts index 78fd63c7d..b7e36d05b 100644 --- a/core/field_input.ts +++ b/core/field_input.ts @@ -186,6 +186,7 @@ export abstract class FieldInput extends Field { */ protected override doValueInvalid_(_invalidValue: AnyDuringMigration) { if (this.isBeingEdited_) { + this.isDirty_ = true; this.isTextValid_ = false; const oldValue = this.value_; // Revert value when the text becomes invalid. @@ -207,12 +208,9 @@ export abstract class FieldInput extends Field { * that this is a string. */ protected override doValueUpdate_(newValue: AnyDuringMigration) { + this.isDirty_ = true; this.isTextValid_ = true; this.value_ = newValue; - if (!this.isBeingEdited_) { - // This should only occur if setValue is triggered programmatically. - this.isDirty_ = true; - } } /** @@ -383,7 +381,6 @@ export abstract class FieldInput extends Field { htmlInput.value = htmlInput.defaultValue = this.getEditorText_(this.value_); htmlInput.setAttribute('data-untyped-default-value', this.value_); - htmlInput.setAttribute('data-old-value', ''); this.resizeEditor_(); @@ -493,15 +490,7 @@ export abstract class FieldInput extends Field { * @param _e Keyboard event. */ private onHtmlInputChange_(_e: Event) { - const text = this.htmlInput_!.value; - if (text !== this.htmlInput_!.getAttribute('data-old-value')) { - this.htmlInput_!.setAttribute('data-old-value', text); - - const value = this.getValueFromEditorText_(text); - this.setValue(value); - this.forceRerender(); - this.resizeEditor_(); - } + this.setValue(this.getValueFromEditorText_(this.htmlInput_!.value)); } /** diff --git a/tests/mocha/blocks/procedures_test.js b/tests/mocha/blocks/procedures_test.js index 98bdf6e9d..0e5e944c3 100644 --- a/tests/mocha/blocks/procedures_test.js +++ b/tests/mocha/blocks/procedures_test.js @@ -484,10 +484,9 @@ suite('Procedures', function() { test('Simple, Input', function() { const defInput = this.defBlock.getField('NAME'); defInput.htmlInput_ = document.createElement('input'); - defInput.htmlInput_.setAttribute('data-old-value', 'proc name'); defInput.htmlInput_.setAttribute('data-untyped-default-value', 'proc name'); - defInput.htmlInput_.value = defInput.htmlInput_.getAttribute('data-old-value') + '2'; + defInput.htmlInput_.value = 'proc name2'; defInput.onHtmlInputChange_(null); chai.assert.equal( this.defBlock.getFieldValue('NAME'), 'proc name2'); @@ -497,7 +496,6 @@ suite('Procedures', function() { test('lower -> CAPS', function() { const defInput = this.defBlock.getField('NAME'); defInput.htmlInput_ = document.createElement('input'); - defInput.htmlInput_.setAttribute('data-old-value', 'proc name'); defInput.htmlInput_.setAttribute('data-untyped-default-value', 'proc name'); defInput.htmlInput_.value = 'PROC NAME'; @@ -512,7 +510,6 @@ suite('Procedures', function() { this.callBlock.setFieldValue('PROC NAME', 'NAME'); const defInput = this.defBlock.getField('NAME'); defInput.htmlInput_ = document.createElement('input'); - defInput.htmlInput_.setAttribute('data-old-value', 'PROC NAME'); defInput.htmlInput_.setAttribute('data-untyped-default-value', 'PROC NAME'); defInput.htmlInput_.value = 'proc name'; @@ -525,10 +522,9 @@ suite('Procedures', function() { test('Whitespace', function() { const defInput = this.defBlock.getField('NAME'); defInput.htmlInput_ = document.createElement('input'); - defInput.htmlInput_.setAttribute('data-old-value', 'proc name'); defInput.htmlInput_.setAttribute('data-untyped-default-value', 'proc name'); - defInput.htmlInput_.value = defInput.htmlInput_.getAttribute('data-old-value') + ' '; + defInput.htmlInput_.value = 'proc name '; defInput.onHtmlInputChange_(null); chai.assert.equal( this.defBlock.getFieldValue('NAME'), 'proc name'); @@ -538,12 +534,11 @@ suite('Procedures', function() { test('Whitespace then Text', function() { const defInput = this.defBlock.getField('NAME'); defInput.htmlInput_ = document.createElement('input'); - defInput.htmlInput_.setAttribute('data-old-value', 'proc name'); defInput.htmlInput_.setAttribute('data-untyped-default-value', 'proc name'); - defInput.htmlInput_.value = defInput.htmlInput_.getAttribute('data-old-value') + ' '; + defInput.htmlInput_.value = 'proc name '; defInput.onHtmlInputChange_(null); - defInput.htmlInput_.value = defInput.htmlInput_.getAttribute('data-old-value') + '2'; + defInput.htmlInput_.value = 'proc name 2'; defInput.onHtmlInputChange_(null); chai.assert.equal( this.defBlock.getFieldValue('NAME'), 'proc name 2'); @@ -553,7 +548,6 @@ suite('Procedures', function() { test('Set Empty', function() { const defInput = this.defBlock.getField('NAME'); defInput.htmlInput_ = document.createElement('input'); - defInput.htmlInput_.setAttribute('data-old-value', 'proc name'); defInput.htmlInput_.setAttribute('data-untyped-default-value', 'proc name'); defInput.htmlInput_.value = ''; @@ -568,7 +562,6 @@ suite('Procedures', function() { test('Set Empty, and Create New', function() { const defInput = this.defBlock.getField('NAME'); defInput.htmlInput_ = document.createElement('input'); - defInput.htmlInput_.setAttribute('data-old-value', 'proc name'); defInput.htmlInput_.setAttribute('data-untyped-default-value', 'proc name'); defInput.htmlInput_.value = '';