Skip to content

Commit

Permalink
Enhance base input validation (#184)
Browse files Browse the repository at this point in the history
  • Loading branch information
nilmerg authored Aug 10, 2023
2 parents 2bdc270 + 20afc0e commit f515e9a
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions asset/js/widget/BaseInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ define(["../notjQuery", "Completer"], function ($, Completer) {
this.usedTerms = [];
this.completer = null;
this.lastCompletedTerm = null;
this.manageRequired = input.required;
this._dataInput = null;
this._termInput = null;
this._termContainer = null;
Expand Down Expand Up @@ -147,7 +148,15 @@ define(["../notjQuery", "Completer"], function ($, Completer) {
this.togglePlaceholder();
}

return this.hasTerms();
if (this.hasTerms()) {
if (this.manageRequired) {
this.input.required = false;
}

return true;
}

return false;
}

registerTerms() {
Expand Down Expand Up @@ -951,13 +960,19 @@ define(["../notjQuery", "Completer"], function ($, Completer) {
}

if (this.hasTerms()) {
this.input.required = false;
if (this.manageRequired) {
this.input.required = false;
}

// This is not part of `onSubmit()` because otherwise it would override what `autoSubmit()` does
this.dataInput.value = JSON.stringify({ type: 'submit', terms: this.usedTerms });
} else if (typeof this.input.dataset.manageRequired !== 'undefined') {

return;
} else if (this.manageRequired && ! this.hasTerms()) {
this.input.required = true;
}

this.dataInput.value = '';
}

onPaste(event) {
Expand Down

0 comments on commit f515e9a

Please sign in to comment.