cocoon-vanilla-js
cocoon-vanilla-js copied to clipboard
Getting the actual inserted element
Current API Implementation
...
// node is HTML string.
insertionNodeElem.insertAdjacentHTML(insertionMethod, node);
insertionNodeElem.dispatchEvent(
new CustomEvent('cocoon:after-insert', {detail: node, bubbles: true, cancelable: true})
);
Proposed implementation
...
// node is HTML string.
var inserted = insertionNodeElem.insertAdjacentHTML(insertionMethod, node);
insertionNodeElem.dispatchEvent(
new CustomEvent('cocoon:after-insert', {detail: [node, inserted], bubbles: true, cancelable: true})
);
This would allow to interact with the inserted element. There is no way to get the generated ID either so it makes finding it harder. We currently need to get the container and check for last element before the add button.
Another fork example I havn't tested https://github.com/dabroz/cocoon-js-vanilla/blob/master/index.js#L118
For what it's worth, that support was added in another implementation: https://github.com/dabroz/cocoon-js-vanilla/pull/9/files