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 May 16, 2022
1 parent 2cbde3e commit 08511c0
Showing 1 changed file with 35 additions and 2 deletions.
37 changes: 35 additions & 2 deletions asset/js/widget/TermInput.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
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.input.dataset.termSeparator : ' ';
this.ignoreSpaceUntil = null;
this.ignoreSpaceSince = null;
}

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

reset() {
super.reset();

Expand Down Expand Up @@ -61,6 +66,26 @@ 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"><i class="fa fa-trash term-icon"></i></label>');

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

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 +147,14 @@ define(["BaseInput"], function (BaseInput) {
}
}
}

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

return TermInput;
Expand Down

0 comments on commit 08511c0

Please sign in to comment.