Skip to content

Commit

Permalink
TermInput: Add attr data-term-separator and code for term read-only…
Browse files Browse the repository at this point in the history
… mode
  • Loading branch information
sukhwinder33445 committed Aug 29, 2022
1 parent be6b59a commit d17b807
Showing 1 changed file with 42 additions and 2 deletions.
44 changes: 42 additions & 2 deletions asset/js/widget/TermInput.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
define(["BaseInput"], function (BaseInput) {
define(["../notjQuery", "BaseInput"], function ($, BaseInput) {

"use strict";

class TermInput extends BaseInput {
constructor(input) {
super(input);

this.separator = ' ';
this.separator = this.input.dataset.termSeparator || ' ';
this.ignoreSpaceUntil = null;
this.ignoreSpaceSince = null;
}

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

return super.bind();
}

reset() {
super.reset();

Expand Down Expand Up @@ -61,6 +69,32 @@ define(["BaseInput"], function (BaseInput) {
super.complete(input, data);
}

renderTerm(termData, termIndex) {
if (! this.isReadOnlyMode()) {
return super.renderTerm(termData, termIndex);
}

let label = $.render(
'<label><input type="button" class="term-badge"><i class="fa fa-trash trash-icon"></i></label>'
);

if (termData.class) {
label.classList.add(termData.class);
}

if (termData.title) {
label.title = termData.title;
}

label.dataset.label = termData.label;
label.dataset.search = termData.search;
label.dataset.index = termIndex;

label.firstChild.value = termData.label;

return label;
}

/**
* Event listeners
*/
Expand Down Expand Up @@ -122,6 +156,12 @@ define(["BaseInput"], function (BaseInput) {
}
}
}

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

return TermInput;
Expand Down

0 comments on commit d17b807

Please sign in to comment.