.match() fails when using group selector
Reported by wiktor | September 1st, 2008 @ 11:20 PM | in 1.6.0.4
When using group selector in match and the target element doesn't match to the first group match() returns false.
console.log($$("div").first().match("div, p") == $$("div").first().match("p, div"));
false
I did a page with more examples.
http://devidens.hu/prototype/200...
It's not browser specific. I tested under XP with FF2, IE7, O9.22 and all fail.
Comments and changes to this ticket
-
Andrew Dupont September 1st, 2008 @ 11:33 PM
- → Milestone changed from to 1.6.0.3
- → State changed from new to bug
-
Juriy Zaytsev September 2nd, 2008 @ 06:05 AM
We could change
matchinto:match: function(element, selector) { if (Object.isString(selector)) selector = Selector.split(selector).map(function(s) { return new Selector(s) }); if (!('any' in selector)) selector = [selector]; return selector.any(function(s){ return s.match($(element)) }); },This feels too "heavy" though.
I would be in favor of making
Selectorinstance support comma-separated expression (both when instantiating and executingmatch)Thoughts?
-
Mark Caudill September 2nd, 2008 @ 06:52 AM
I definitely agree having 3 instances of Selector for a group selector is too much. I would also have to agree Selector should support it upon instantiation and while using match.
For this bug, I would imagine you could just call match recursively and just set match to false and break. Unless I'm wrong, it just needs to use indexOf to find a comma.
-
John-David Dalton September 3rd, 2008 @ 05:57 PM
We could make Element#match use Selector.findChildElements, combined with Kangax's mod to Selector.findChildElements for http://prototype.lighthouseapp.com/projects/8886/tickets/262-element-down-does-not-always-match-first-element
-
John-David Dalton September 3rd, 2008 @ 05:58 PM
- → Title changed from wiktor .match() fails when using group selector to .match() fails when using group selector
edited posts to not distract from the bug.
-
Juriy Zaytsev September 4th, 2008 @ 01:54 AM
Mark,
I'm not sure what you mean by using
indexOf, butSelector.splitis there to ensure complex selectors are parsed properly, e.g.:[name*="foo,bar"], div.blah -
Tobie Langel October 1st, 2008 @ 01:55 PM
- → Milestone cleared.
-
Andrew Dupont October 3rd, 2008 @ 10:48 PM
- → Milestone changed from to 1.6.0.4
-
GitHub Robot November 29th, 2008 @ 05:31 AM
- → State changed from bug to resolved
(from [afd74ce1c72a17666d8c9d86131463ad73cafe9e]) Enhance Selector#match to support a "group" (comma-separated) selector. [#318 state:resolved] http://github.com/sstephenson/pr...
Please Login or create a free account to add a new comment.
You can update this ticket by sending an email to from your email client. (help)
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
The Prototype JavaScript library.
