Group value callback tweaks

This commit is contained in:
Josh Johnson 2016-10-18 19:39:49 +01:00
parent 5cc10cdcbb
commit 5c04638bef
2 changed files with 12 additions and 17 deletions

View file

@ -731,7 +731,7 @@ class Choices {
if (foundChoice) {
if (!foundChoice.selected) {
this._addItem(foundChoice.value, foundChoice.label, foundChoice.id);
this._addItem(foundChoice.value, foundChoice.label, foundChoice.id, foundChoice.groupId);
} else {
console.warn('Attempting to select choice already selected');
}
@ -1817,7 +1817,6 @@ class Choices {
const items = this.store.getItems();
const passedLabel = label || passedValue;
const passedOptionId = parseInt(choiceId, 10) || -1;
const passedGroupId = parseInt(groupId, 10) || -1;
// If a prepended value has been passed, prepend it
if (this.config.prependValue) {
@ -1832,7 +1831,7 @@ class Choices {
// Generate unique id
const id = items ? items.length + 1 : 1;
this.store.dispatch(addItem(passedValue, passedLabel, id, passedOptionId, passedGroupId));
this.store.dispatch(addItem(passedValue, passedLabel, id, passedOptionId, groupId));
if (this.passedElement.type === 'select-one') {
this.removeActiveItems(id);
@ -1841,7 +1840,7 @@ class Choices {
// Run callback if it is a function
if (this.config.callbackOnAddItem) {
const callback = this.config.callbackOnAddItem;
const group = this.store.getGroupById(passedGroupId);
const group = this.store.getGroupById(groupId);
if (isType('Function', callback)) {
if(group && group.value) {
callback(id, passedValue, group.value);

View file

@ -262,11 +262,11 @@
editItems: true,
maxItemCount: 5,
removeItemButton: true,
callbackOnHighlightItem: function(id, value, passedInput) {
// console.log(value);
callbackOnHighlightItem: function(id, value) {
console.log(value);
},
callbackOnUnhighlightItem: function(id, value, passedInput) {
// console.log(value);
callbackOnUnhighlightItem: function(id, value) {
console.log(value);
},
});
@ -296,12 +296,6 @@
});
var multipleDefault = new Choices('#choices-multiple-groups', {
callbackOnHighlightItem: function(id, value, groupValue) {
console.log(arguments);
},
callbackOnUnhighlightItem: function(id, value, groupValue) {
console.log(arguments);
},
callbackOnAddItem: function(id, value, groupValue) {
console.log(arguments);
},
@ -314,7 +308,9 @@
placeholder: true,
placeholderValue: 'Pick an Strokes record',
maxItemCount: 5,
// callbackOnChange: function(value, passedInput) { console.log(value) }
callbackOnChange: function(value) {
console.log(value)
}
}).ajax(function(callback) {
fetch('https://api.discogs.com/artists/55980/releases?token=QBRmstCkwXEvCjTclCpumbtNwvVkEzGAdELXyRyW')
.then(function(response) {
@ -323,7 +319,7 @@
});
})
.catch(function(error) {
// console.log(error);
// console.error(error);
});
});
@ -343,7 +339,7 @@
});
})
.catch(function(error) {
// console.log(error);
// console.error(error);
});
});