mirror of
https://github.com/Choices-js/Choices.git
synced 2024-05-21 15:06:45 +02:00
Destroy method tweaks
This commit is contained in:
parent
0b27522e2b
commit
57ad1dc31c
4
assets/scripts/dist/choices.min.js
vendored
4
assets/scripts/dist/choices.min.js
vendored
File diff suppressed because one or more lines are too long
|
@ -316,8 +316,14 @@ export class Choices {
|
||||||
// We are typing into a text input and have a value, we want to show a dropdown
|
// We are typing into a text input and have a value, we want to show a dropdown
|
||||||
// notice. Otherwise hide the dropdown
|
// notice. Otherwise hide the dropdown
|
||||||
if(this.passedElement.type === 'text') {
|
if(this.passedElement.type === 'text') {
|
||||||
|
let dropdownItem;
|
||||||
if(this.input.value) {
|
if(this.input.value) {
|
||||||
const dropdownItem = this.getTemplate('notice', `Add "${ this.input.value }"`);
|
if (this.options.maxItems && this.options.maxItems <= this.list.children.length) {
|
||||||
|
dropdownItem = this.getTemplate('notice', `Only ${ this.options.maxItems } options can be selected.`);
|
||||||
|
} else {
|
||||||
|
dropdownItem = this.getTemplate('notice', `Add "${ this.input.value }"`);
|
||||||
|
}
|
||||||
|
|
||||||
this.dropdown.innerHTML = dropdownItem.outerHTML;
|
this.dropdown.innerHTML = dropdownItem.outerHTML;
|
||||||
if(!this.dropdown.classList.contains(this.options.classNames.activeState)) {
|
if(!this.dropdown.classList.contains(this.options.classNames.activeState)) {
|
||||||
this.showDropdown();
|
this.showDropdown();
|
||||||
|
@ -1166,11 +1172,20 @@ export class Choices {
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
destroy() {
|
destroy() {
|
||||||
|
this.passedElement.classList.remove(this.options.classNames.input, this.options.classNames.hiddenState);
|
||||||
|
this.passedElement.tabIndex = '';
|
||||||
|
this.passedElement.removeAttribute('style', 'display:none;');
|
||||||
|
this.passedElement.removeAttribute('aria-hidden');
|
||||||
|
|
||||||
|
this.containerOuter.outerHTML = this.passedElement.outerHTML;
|
||||||
|
|
||||||
this.passedElement = null;
|
this.passedElement = null;
|
||||||
this.userOptions = null;
|
this.userOptions = null;
|
||||||
this.options = null;
|
this.options = null;
|
||||||
this.initialised = null;
|
this.initialised = null;
|
||||||
this.store = null;
|
this.store = null;
|
||||||
|
|
||||||
|
this.removeEventListeners();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
<label for="choices-3">Text input that only allows email addresses</label>
|
<label for="choices-3">Text input that only allows email addresses</label>
|
||||||
<input id="choices-3" type="text" placeholder="This is a placeholder">
|
<input id="choices-3" type="text" placeholder="This is a placeholder">
|
||||||
|
|
||||||
<label for="choices-4">Text input that disables adding items</label>
|
<label for="choices-4">Text input that disables adding items (destroyed)</label>
|
||||||
<input id="choices-4" type="text" value="josh@joshuajohnson.co.uk, joe@bloggs.co.uk" placeholder="This is a placeholder">
|
<input id="choices-4" type="text" value="josh@joshuajohnson.co.uk, joe@bloggs.co.uk" placeholder="This is a placeholder">
|
||||||
|
|
||||||
<label for="choices-5">Text input that prepends and appends a value to each items return value</label>
|
<label for="choices-5">Text input that prepends and appends a value to each items return value</label>
|
||||||
|
@ -128,6 +128,8 @@
|
||||||
removeItems: false,
|
removeItems: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
choices4.destroy();
|
||||||
|
|
||||||
const choices5 = new Choices('#choices-5', {
|
const choices5 = new Choices('#choices-5', {
|
||||||
prependValue: 'item-',
|
prependValue: 'item-',
|
||||||
appendValue: `-${Date.now()}`,
|
appendValue: `-${Date.now()}`,
|
||||||
|
|
Loading…
Reference in a new issue