-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to prevent duplicates on multidrag #2387
Comments
I solved by adding elements in an array in It would be nice if the MultiDrag Plugin had an option like |
Would you show how you solved it?
async initMovability() {
await this.updateComplete;
const boardColumns = this.shadowRoot!.querySelectorAll('.board-column .board-items');
boardColumns.forEach(column => {
Sortable.create(column as HTMLElement, {
group: 'board',
animation: 300,
onEnd: (evt) => {
const itemEl = evt.item;
const newState = itemEl.closest('.board-column')?.id as COLUMN_STATE;
if (!itemEl.dataset.id) {
throw new Error('"data-set-id" not found, but it\'s required for sorting.')
}
if (newState) {
this._boardCardContext?.updateCardState(itemEl.dataset.id!, newState);
this.requestUpdate();
}
}
});
});
} So, you say, you added an optional parameter to group and you check on onAdd if there are duplicates and you skip them. async initMovability() {
await this.updateComplete;
const boardColumns = this.shadowRoot!.querySelectorAll('.board-column .board-items');
boardColumns.forEach(column => {
Sortable.create(column as HTMLElement, {
group: {
name: "board",
pull: true,
put: true
},
animation: 300,
onAdd: (evt) => {
const newList = evt.to as HTMLElement;
const itemEl = evt.item;
if (!itemEl.dataset.id) {
throw new Error('Data-set-id not found, but it\'s required for sorting.');
}
const newState = newList.closest('.board-column')?.id as COLUMN_STATE;
if (newState) {
this._boardCardContext?.updateCardState(itemEl.dataset.id!, newState);
}
},
onRemove: (evt) => {
// Somehow this ensures that duplicates are removed after moving
const newList = evt.to as HTMLElement;
newList.removeChild(evt.item);
},
});
});
} |
On the group/put option, i save elemens in to an array group: {
put: (to, from, dragEl, event) => {
// save to arrayName
},
}, and on onAdd function ... onAdd: function (e) {
e.items.forEach(e => {
if (arrayName.includes(...)) {
e.remove();
}
}
}, |
There is a possibility to prevent duplicates on multidrag?
The text was updated successfully, but these errors were encountered: