Opened 11 years ago

Closed 11 years ago

#11458 closed defect (fixed)

[patch] [cla] Nodelist.closest() doesn't match descendant selectors

Reported by: bill Owned by: bill
Priority: high Milestone: 1.6
Component: Core Version: 1.5
Keywords: Cc:
Blocked By: Blocking:


See test case attached to #11457.

dojo.query(".bang").closest(".foo > .bar")

is run on the following HTML:

<div id="level3" class="foo">
	<div id="level4" class="bar">
		<div id="level5" class="bar">
			<div id="level6" class="bang">foo bar bar bang</div>

Closest() should find "level4" but it doesn't, it returns []. Similarly this query should also find "level4", but it doesn't:

dojo.query(".bang").closest(".foo .bar")

The patch in #11457 fixes this bug.

Attachments (1)

11458-test.diff (908 bytes) - added by ben hockey 11 years ago.

Download all attachments as: .zip

Change History (6)

comment:1 Changed 11 years ago by bill

Milestone: tbd1.6
Owner: changed from anonymous to bill
Status: newassigned

comment:2 Changed 11 years ago by bill

Resolution: fixed
Status: assignedclosed

(In [22528]) Fix/enhance dojo._filterQueryResult(), NodeList.closest(), NodeList.orphan(), and NodeList.filter() to work on descendant selectors like "div > span", yet to work efficiently for simple selectors like ".foo". Fixes #11457, #11458 !strict.

Also, enhanced NodeList.closest() to take an optional root parameter (same as dojo.query()'s root parameter). If root is specified, the selector is relative to that node rather than the document root. This parameter will be useful for future NodeList.delegate(). Refs #11459.

comment:3 Changed 11 years ago by ben hockey

Resolution: fixed
Status: closedreopened
dojo.query('.bang').closest('> .bar', 'level3');

should find ['level4'] but doesn't. attaching a patch for tests to include this case.

Changed 11 years ago by ben hockey

Attachment: 11458-test.diff added

comment:4 Changed 11 years ago by bill

Good catch, there are a couple problems you've found, in that

dojo.query('.bang').closest('> .bar');

wasn't working correctly either (it should return no results since there are no .bar directly under <body>. I'll patch up the code adding your testcase and another one too.

comment:5 Changed 11 years ago by bill

Resolution: fixed
Status: reopenedclosed

(In [22537]) Make simple-filter check stricter, so that "> div" isn't classified as a simple filter. Also remove query argument from closest()'s call to _getRelatedUniqueNodes(), since it seems unnecessary (the filter has already been applied) and also since it won't work correctly without also passing in the root node that the query is relative to. Fixes #11457, #11458 !strict.

Note: See TracTickets for help on using tickets.