mirror of
https://github.com/Choices-js/Choices.git
synced 2024-06-01 13:32:23 +02:00
Ability to edit last item in list
This commit is contained in:
parent
6228463c71
commit
3f3580bb13
|
@ -18,6 +18,7 @@ export class Choices {
|
||||||
element: document.querySelector('[data-choice]'),
|
element: document.querySelector('[data-choice]'),
|
||||||
disabled: false,
|
disabled: false,
|
||||||
create: true,
|
create: true,
|
||||||
|
editItems: false,
|
||||||
maxItems: false,
|
maxItems: false,
|
||||||
delimiter: ',',
|
delimiter: ',',
|
||||||
allowDuplicates: true,
|
allowDuplicates: true,
|
||||||
|
@ -169,15 +170,13 @@ export class Choices {
|
||||||
|
|
||||||
lastItem.classList.add('is-selected');
|
lastItem.classList.add('is-selected');
|
||||||
|
|
||||||
for (let i = 0; i < currentListItems.length; i++) {
|
if(this.options.editItems) {
|
||||||
let listItem = currentListItems[i];
|
this.input.value = lastItem.innerHTML;
|
||||||
|
this.removeItem(lastItem);
|
||||||
if (listItem.classList.contains('is-selected')) {
|
} else {
|
||||||
this.removeItem(listItem);
|
this.removeAll(currentListItems);
|
||||||
this.removeInputValue(listItem.textContent);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
};
|
|
||||||
|
|
||||||
handleBackspaceKey();
|
handleBackspaceKey();
|
||||||
|
|
||||||
|
@ -247,8 +246,6 @@ export class Choices {
|
||||||
|
|
||||||
// Caste array to string and set it as the hidden inputs value
|
// Caste array to string and set it as the hidden inputs value
|
||||||
this.element.value = this.valueArray.join(this.options.delimiter);
|
this.element.value = this.valueArray.join(this.options.delimiter);
|
||||||
|
|
||||||
console.log(this.element.value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
removeInputValue(value) {
|
removeInputValue(value) {
|
||||||
|
@ -272,6 +269,17 @@ export class Choices {
|
||||||
this.list.appendChild(item);
|
this.list.appendChild(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
removeAll(items) {
|
||||||
|
for (let i = 0; i < items.length; i++) {
|
||||||
|
let item = items[i];
|
||||||
|
|
||||||
|
if (item.classList.contains('is-selected')) {
|
||||||
|
this.removeItem(item);
|
||||||
|
this.removeInputValue(item.textContent);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
removeItem(item) {
|
removeItem(item) {
|
||||||
if (item) item.parentNode.removeChild(item);
|
if (item) item.parentNode.removeChild(item);
|
||||||
}
|
}
|
||||||
|
@ -377,7 +385,8 @@ export class Choices {
|
||||||
|
|
||||||
let choices2 = new Choices({
|
let choices2 = new Choices({
|
||||||
element : input2,
|
element : input2,
|
||||||
allowDuplicates: false
|
allowDuplicates: false,
|
||||||
|
editItems: true
|
||||||
});
|
});
|
||||||
|
|
||||||
let choices3 = new Choices({
|
let choices3 = new Choices({
|
||||||
|
|
Loading…
Reference in a new issue