You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Prefer matching fragments within a given { origin } #197
discovered this when my forms were set to target an inner element, but instead the first matching element on the page was selected (this is a page with a list of forms)
up.selector.closest() doesn't look at children, AFAIK. You might need to narrow the selector if it's ambiguous to Unpoly. If you don't want to add another id or class attribute, you could use up-id.
I wasn't able to follow the exact issue from your example. If you have an opportunity and could make a reproducible example using Glitch, it might help. There's a Glitch template to start you off, if so.
i'm using unpoly ~2.0.1 (whatever is latest on CDN)
i tried many selectors for solutions, even up-id
i spent a lot of time on this issue, trying to figure out why my form post was changing html in some random place on my page, nowhere near the origin.
the way selector closest works either is not intuitive, incorrect, or maybe the function should be renamed.
closest really sounds like it should try to do just querySelector(selector), because the closest selection will be that. but closest is doing a recursive search of parents, so it's name should probably be something similar to what it's actually doing, like search_parents or something
since unpoly has the up-content att, i think i can do an example without needing a server. i'll post it soon.
yes, maybe this should be emphasised in the documentation. i tried to use :origin in my target, but it didn't work, the & is very unfamiliar to me, and i didn't attempt to use it as a selector.
seems that origin should be implied, though.
would be common that the selector you used would break things for people? for me it seems like the intuitive behaviour and & is redundant.
I did try :origin .auto-submit as a selector and it appears to work. The & selector was linked in the v1 up-target docs, but that's not the case for v2. If you think you can make the docs more expressive in this case, please submit a PR. To be honest, & is more familiar to me than :origin, as I have past experience with Sass.
seems that origin should be implied, though.
I haven't ran into any issues here, so I can't really agree. Maybe Henning can provide an opinion here.
I'm going to close this for now since up.fragment.closest documents that it only looks at itself and then it's ancestors, never its children. If Henning deems this a bug we can re-open.
Please feel free to submit a PR for the :origin documentation if you can find a way to improve it.
changed the title [-]up.Selector.closest() doesn't consider selector on children targets[/-][+]Prefer matching fragments within a given { origin }[/+]on Jun 28, 2021
Even without :origin in the selector, Unpoly 2 tries to take a given { origin } into account when matching fragments. Currently that mostly looks for a parent element around the origin.
I haven't had a use case where I needed to auto-match an origin child, but I guess we could support that.
The fix wouldn't go in up.Selector though, but here:
Activity
adam12 commentedon Jun 26, 2021
Can you confirm you're using Unpoly 2?
up.selector.closest()doesn't look at children, AFAIK. You might need to narrow the selector if it's ambiguous to Unpoly. If you don't want to add anotheridorclassattribute, you could useup-id.I wasn't able to follow the exact issue from your example. If you have an opportunity and could make a reproducible example using Glitch, it might help. There's a Glitch template to start you off, if so.
boxxxie commentedon Jun 26, 2021
i'm using
unpoly ~2.0.1(whatever is latest on CDN)i tried many selectors for solutions, even
up-idi spent a lot of time on this issue, trying to figure out why my form post was changing html in some random place on my page, nowhere near the origin.
the way
selector closestworks either is not intuitive, incorrect, or maybe the function should be renamed.closestreally sounds like it should try to do just querySelector(selector), because theclosestselection will be that. but closest is doing a recursive search of parents, so it's name should probably be something similar to what it's actually doing, likesearch_parentsor somethingsince unpoly has the
up-contentatt, i think i can do an example without needing a server. i'll post it soon.boxxxie commentedon Jun 26, 2021
https://glitch.com/edit/#!/ember-mousy-canvas
js has my fix, i can't get the
up-document/up-contentworking (maybe another bug)i added some style to show what unpoly is changing, js has my fix, remove the fix and see the behaviour difference.
adam12 commentedon Jun 26, 2021
I removed your Javascript changes and updated both
up-targetto this.I believe it achieves what you were looking for. Can you confirm? https://glitch.com/edit/#!/radial-attractive-equinox
boxxxie commentedon Jun 26, 2021
yes, maybe this should be emphasised in the documentation. i tried to use :origin in my target, but it didn't work, the
&is very unfamiliar to me, and i didn't attempt to use it as a selector.seems that origin should be implied, though.
would be common that the selector you used would break things for people? for me it seems like the intuitive behaviour and
&is redundant.adam12 commentedon Jun 27, 2021
I did try
:origin .auto-submitas a selector and it appears to work. The&selector was linked in the v1up-targetdocs, but that's not the case for v2. If you think you can make the docs more expressive in this case, please submit a PR. To be honest,&is more familiar to me than:origin, as I have past experience with Sass.I haven't ran into any issues here, so I can't really agree. Maybe Henning can provide an opinion here.
I'm going to close this for now since
up.fragment.closestdocuments that it only looks at itself and then it's ancestors, never its children. If Henning deems this a bug we can re-open.Please feel free to submit a PR for the
:origindocumentation if you can find a way to improve it.[-]up.Selector.closest() doesn't consider selector on children targets[/-][+]Prefer matching fragments within a given { origin }[/+]triskweline commentedon Jun 28, 2021
Both
:originand&are supported, as documented here.Even without
:originin the selector, Unpoly 2 tries to take a given{ origin }into account when matching fragments. Currently that mostly looks for a parent element around the origin.I haven't had a use case where I needed to auto-match an origin child, but I guess we could support that.
The fix wouldn't go in
up.Selectorthough, but here:unpoly/lib/assets/javascripts/unpoly/fragment.coffee
Lines 1033 to 1038 in e555c48
unpoly/lib/assets/javascripts/unpoly/classes/fragment_finder.coffee
Line 11 in e555c48
unpoly/spec_app/spec/javascripts/up/fragment_spec.js.coffee
Lines 63 to 87 in e555c48
triskweline commentedon Jun 28, 2021
Re-opening this issue for a while in case someone wants to tackle that change.