Skip to content

Commit

Permalink
BaseInput.js: Transfer multi term support from FilterInput.js
Browse files Browse the repository at this point in the history
  • Loading branch information
nilmerg committed Aug 7, 2023
1 parent 822c4c7 commit c2793ab
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
22 changes: 16 additions & 6 deletions asset/js/widget/BaseInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ define(["../notjQuery", "Completer"], function ($, Completer) {

readFullTerm(input, termIndex = null) {
let value = this.readPartialTerm(input);
if (! value) {
if (! value && this.lastCompletedTerm === null) {
return false;
}

Expand All @@ -242,11 +242,19 @@ define(["../notjQuery", "Completer"], function ($, Completer) {
termData = { ...this.usedTerms[termIndex] };
}

termData.label = value;
termData.search = value;
if (value) {
termData.label = value;
termData.search = value;
}

if (this.lastCompletedTerm !== null) {
if (termData.label === this.lastCompletedTerm.label) {
if ('type' in this.lastCompletedTerm && this.lastCompletedTerm.type === 'terms') {
if (typeof this.lastCompletedTerm.terms === 'string') {
termData = JSON.parse(this.lastCompletedTerm.terms);
} else {
termData = this.lastCompletedTerm.terms;
}
} else if (termData.label === this.lastCompletedTerm.label) {
Object.assign(termData, this.lastCompletedTerm);
}

Expand Down Expand Up @@ -713,9 +721,11 @@ define(["../notjQuery", "Completer"], function ($, Completer) {
let termIndex = Number(input.parentNode.dataset.index);

this.lastCompletedTerm = termData;
this.writePartialTerm(termData.label, input);

this.checkValidity(input);
if ('label' in termData) {
this.writePartialTerm(termData.label, input);
this.checkValidity(input);
}

if (termIndex >= 0) {
this.autoSubmit(input, 'save', { terms: { [termIndex]: this.saveTerm(input, false, true) } });
Expand Down
8 changes: 2 additions & 6 deletions asset/js/widget/FilterInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,8 @@ define(["../notjQuery", "BaseInput"], function ($, BaseInput) {
return false;
}

if (termData.type === 'terms') {
termData = JSON.parse(termData.terms);
} else {
if (! termData.type) {
termData.type = this.termType;
}
if (! Array.isArray(termData) && ! termData.type) {
termData.type = this.termType;
}

return termData;
Expand Down

0 comments on commit c2793ab

Please sign in to comment.