fix: not being able to set field values to empty (#6702)

This commit is contained in:
Beka Westberg
2022-12-15 01:08:15 +00:00
committed by GitHub
parent 73cdc7410f
commit 658e14ff75
2 changed files with 7 additions and 25 deletions

View File

@@ -186,6 +186,7 @@ export abstract class FieldInput<T extends InputTypes> extends Field<T> {
*/
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<T extends InputTypes> extends Field<T> {
* 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<T extends InputTypes> extends Field<T> {
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<T extends InputTypes> extends Field<T> {
* @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));
}
/**

View File

@@ -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 = '';