Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 3 additions & 14 deletions core/field_input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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;
}
}

/**
Expand Down Expand Up @@ -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_();

Expand Down Expand Up @@ -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));
}

/**
Expand Down
15 changes: 4 additions & 11 deletions tests/mocha/blocks/procedures_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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';
Expand All @@ -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';
Expand All @@ -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');
Expand All @@ -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');
Expand All @@ -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 = '';
Expand All @@ -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 = '';
Expand Down