Destroy method tweaks

This commit is contained in:
Josh Johnson 2016-05-07 14:14:05 +01:00
parent 0b27522e2b
commit 57ad1dc31c
3 changed files with 21 additions and 4 deletions

File diff suppressed because one or more lines are too long

View file

@ -316,8 +316,14 @@ export class Choices {
// We are typing into a text input and have a value, we want to show a dropdown
// notice. Otherwise hide the dropdown
if(this.passedElement.type === 'text') {
let dropdownItem;
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;
if(!this.dropdown.classList.contains(this.options.classNames.activeState)) {
this.showDropdown();
@ -1166,11 +1172,20 @@ export class Choices {
* @return
*/
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.userOptions = null;
this.options = null;
this.initialised = null;
this.store = null;
this.removeEventListeners();
}
};

View file

@ -20,7 +20,7 @@
<label for="choices-3">Text input that only allows email addresses</label>
<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">
<label for="choices-5">Text input that prepends and appends a value to each items return value</label>
@ -128,6 +128,8 @@
removeItems: false,
});
choices4.destroy();
const choices5 = new Choices('#choices-5', {
prependValue: 'item-',
appendValue: `-${Date.now()}`,