Skip to content

Commit

Permalink
Fix duplication JS
Browse files Browse the repository at this point in the history
  • Loading branch information
javihgil committed Nov 24, 2023
1 parent d3ddbcf commit 27ba8a8
Showing 1 changed file with 3 additions and 10 deletions.
13 changes: 3 additions & 10 deletions assets/scripts/polymorphic-form-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -468,18 +468,11 @@ function moveDownPolymorphicNode(collection, node) {
}

function duplicatePolymorphicNode(collection, node) {
const nodes = [...collection.querySelectorAll(':scope > [data-polymorphic=node]')];
const currentNodeIndex = nodes.indexOf(node);

let newNode = node.cloneNode(true);
const nextNode = node.nextElementSibling;

collection.appendChild(newNode);

if (nodes[currentNodeIndex+1] !== undefined) {
const nextNode = nodes[currentNodeIndex+1];
nextNode.parentNode.insertBefore(newNode, nextNode);
modifyIndexes(newNode, +1);
}
nextNode.parentNode.insertBefore(newNode, nextNode);
modifyIndexes(newNode, +1);

return newNode;
}
Expand Down

0 comments on commit 27ba8a8

Please sign in to comment.