Skip to content
Snippets Groups Projects
Commit d097ead5 authored by Robert Phillips's avatar Robert Phillips
Browse files

Issue #3309894 by robphillips: Fix issues with values checker.

parent 3e4242c5
No related branches found
No related tags found
No related merge requests found
......@@ -32,12 +32,12 @@
item: "choices__item choices__item--autocomplete",
},
});
if (this.choices.getValue()) {
if (this.hasValues()) {
this.choices.containerOuter.element.classList.add("is-filled");
}
element.addEventListener("change", () => {
this.clear.bind(this);
if (this.choices.getValue()) {
if (this.hasValues()) {
this.choices.containerOuter.element.classList.add("is-filled");
} else {
this.choices.containerOuter.element.classList.remove("is-filled");
......@@ -114,6 +114,17 @@
);
}
/**
* Check if value(s) exist.
*
* @returns {true|false}
* Returns TRUE or FALSE.
*/
hasValues() {
const values = this.choices.getValue();
return (Array.isArray(values) && values.length) || (!Array.isArray(values) && values);
}
/**
* Check for max selected items.
*
......
......@@ -25,14 +25,14 @@
}
});
if (this.choices.getValue()) {
if (this.hasValues()) {
this.choices.containerOuter.element.classList.add("is-filled");
}
element.addEventListener("change", () => {
this.clear.bind(this);
if (this.choices.getValue()) {
if (this.hasValues()) {
this.choices.containerOuter.element.classList.add("is-filled");
} else {
this.choices.containerOuter.element.classList.remove("is-filled");
......@@ -90,6 +90,11 @@
this.choices.choiceList.append(this.choices._getTemplate("notice", message));
}
hasValues() {
const values = this.choices.getValue();
return Array.isArray(values) && values.length || !Array.isArray(values) && values;
}
isMax() {
return this.choices.config.maxItemCount > 1 && this.choices.getValue(true).length >= this.choices.config.maxItemCount;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment