Skip to content
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

Getting the actual inserted element #19

Open
james-em opened this issue Aug 11, 2022 · 1 comment
Open

Getting the actual inserted element #19

james-em opened this issue Aug 11, 2022 · 1 comment
Assignees

Comments

@james-em
Copy link

james-em commented Aug 11, 2022

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

@james-em
Copy link
Author

james-em commented Oct 6, 2022

For what it's worth, that support was added in another implementation: https://github.com/dabroz/cocoon-js-vanilla/pull/9/files

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants