Skip to content

Commit

Permalink
TermInput: Support read only terms
Browse files Browse the repository at this point in the history
Co-authored-by: Johannes Meyer <[email protected]>
  • Loading branch information
sukhwinder33445 and nilmerg committed May 3, 2024
1 parent 24b5f17 commit f12f188
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions asset/js/widget/TermInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,17 @@ define(["../notjQuery", "BaseInput"], function ($, BaseInput) {
super(input);

this.separator = this.input.dataset.termSeparator || ' ';
this.readOnly = 'readOnlyTerms' in this.input.dataset;
this.ignoreSpaceUntil = null;
}

bind() {
super.bind();

if (this.readOnly) {
$(this.termContainer).on('click', '[data-index] > input', this.onTermClick, this);
}

// TODO: Compatibility only. Remove as soon as possible once Web 2.12 (?) is out.
// Or upon any other update which lets Web trigger a real submit upon auto submit.
$(this.input.form).on('change', 'select.autosubmit', this.onSubmit, this);
Expand Down Expand Up @@ -90,10 +95,27 @@ define(["../notjQuery", "BaseInput"], function ($, BaseInput) {
super.complete(input, data);
}

renderTerm(termData, termIndex) {
const label = super.renderTerm(termData, termIndex);

if (this.readOnly) {
label.firstChild.type = 'button';
label.appendChild($.render('<i class="fa fa-trash trash-icon"></i>'));
}

return label;
}

/**
* Event listeners
*/

onTermClick(event) {
let termIndex = Number(event.target.parentNode.dataset.index);
this.removeTerm(event.target.parentNode);
this.moveFocusForward(termIndex - 1);
}

onSubmit(event) {
super.onSubmit(event);

Expand Down

0 comments on commit f12f188

Please sign in to comment.