mirror of
https://github.com/Choices-js/Choices.git
synced 2024-06-18 13:45:12 +02:00
Group value callback tweaks
This commit is contained in:
parent
5cc10cdcbb
commit
5c04638bef
|
@ -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);
|
||||
|
|
22
index.html
22
index.html
|
@ -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);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in a new issue