Add dropdown items

This commit is contained in:
Josh Johnson 2016-04-10 22:54:56 +01:00
parent c821c923c9
commit f05b49578a
2 changed files with 14 additions and 4 deletions

File diff suppressed because one or more lines are too long

View file

@ -36,7 +36,11 @@ export class Choices {
prependValue: false, prependValue: false,
appendValue: false, appendValue: false,
selectAll: true, selectAll: true,
classNames: {}, classNames: {
input: '',
container: '',
},
callbackOnInit: function() {}, callbackOnInit: function() {},
callbackOnRender: function() {}, callbackOnRender: function() {},
callbackOnRemoveItem: function() {}, callbackOnRemoveItem: function() {},
@ -236,6 +240,12 @@ export class Choices {
handleClick(item); handleClick(item);
} }
if(e.target.hasAttribute('data-choice-selectable')) {
let item = e.target;
let value = e.target.getAttribute('data-choice-value');
this.addItem(value);
}
} }
onFocus(e) { onFocus(e) {
@ -578,14 +588,14 @@ export class Choices {
addEventListeners() { addEventListeners() {
document.addEventListener('keydown', this.onKeyDown); document.addEventListener('keydown', this.onKeyDown);
this.list.addEventListener('click', this.onClick); this.containerOuter.addEventListener('click', this.onClick);
this.input.addEventListener('focus', this.onFocus); this.input.addEventListener('focus', this.onFocus);
this.input.addEventListener('blur', this.onBlur); this.input.addEventListener('blur', this.onBlur);
} }
removeEventListeners() { removeEventListeners() {
document.removeEventListener('keydown', this.onKeyDown); document.removeEventListener('keydown', this.onKeyDown);
this.list.removeEventListener('click', this.onClick); this.containerOuter.removeEventListener('click', this.onClick);
this.input.removeEventListener('focus', this.onFocus); this.input.removeEventListener('focus', this.onFocus);
this.input.removeEventListener('blur', this.onBlur); this.input.removeEventListener('blur', this.onBlur);
} }