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

Restrict lookup for new item template to the closest item if exists #62

Merged
merged 2 commits into from
Feb 10, 2024

Conversation

gael-ian
Copy link
Member

This should fix #61.

When a form uses Cocooned on multiple nested levels, the name data attribute of the template used to build new grand-child item does not change between child item (as all where built from the same template). If multiple child item are added to the form at the same time and each contains an add trigger to build new grand-child items, they will all share the same template name.

So far, lookup was done with document.querySelector but this will always return the first template with a matching name, the one of the first built child item. The options extractor will now look only inside the closest cocooned item to find the template and instantiate a builder with the correct template.

As a fallback, if no template is found, it will still look through the whole document so top-level Cocooned instance can still have their add triggers (and their associated template) anywhere.

@gael-ian gael-ian merged commit f38e864 into main Feb 10, 2024
13 checks passed
@gael-ian gael-ian deleted the nested-cocooned-incorrectly-assigned-on-save branch February 10, 2024 19:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Nested cocooneds are incorrectly assigned in certain situations
1 participant