Skip to content

Commit f12f188

Browse files
TermInput: Support read only terms
Co-authored-by: Johannes Meyer <johannes.meyer@icinga.com>
1 parent 24b5f17 commit f12f188

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

asset/js/widget/TermInput.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,17 @@ define(["../notjQuery", "BaseInput"], function ($, BaseInput) {
77
super(input);
88

99
this.separator = this.input.dataset.termSeparator || ' ';
10+
this.readOnly = 'readOnlyTerms' in this.input.dataset;
1011
this.ignoreSpaceUntil = null;
1112
}
1213

1314
bind() {
1415
super.bind();
1516

17+
if (this.readOnly) {
18+
$(this.termContainer).on('click', '[data-index] > input', this.onTermClick, this);
19+
}
20+
1621
// TODO: Compatibility only. Remove as soon as possible once Web 2.12 (?) is out.
1722
// Or upon any other update which lets Web trigger a real submit upon auto submit.
1823
$(this.input.form).on('change', 'select.autosubmit', this.onSubmit, this);
@@ -90,10 +95,27 @@ define(["../notjQuery", "BaseInput"], function ($, BaseInput) {
9095
super.complete(input, data);
9196
}
9297

98+
renderTerm(termData, termIndex) {
99+
const label = super.renderTerm(termData, termIndex);
100+
101+
if (this.readOnly) {
102+
label.firstChild.type = 'button';
103+
label.appendChild($.render('<i class="fa fa-trash trash-icon"></i>'));
104+
}
105+
106+
return label;
107+
}
108+
93109
/**
94110
* Event listeners
95111
*/
96112

113+
onTermClick(event) {
114+
let termIndex = Number(event.target.parentNode.dataset.index);
115+
this.removeTerm(event.target.parentNode);
116+
this.moveFocusForward(termIndex - 1);
117+
}
118+
97119
onSubmit(event) {
98120
super.onSubmit(event);
99121

0 commit comments

Comments
 (0)