Ticket #4425 (closed defect: fixed)

Opened 22 months ago

Last modified 3 months ago

[patch][ccla] Query doesn't handle queries by ID relative to a root node properly

Reported by: guest Owned by: alex
Priority: normal Milestone: 1.3
Component: Core Version: 0.9
Severity: normal Keywords:
Cc: ben.schell@…

Description (last modified by dmachi) (diff)

Lets say I have an HTML DOM element that does not belong to the current rendered page (maybe it was fetched from a remote page, or created programmatically). I then want to do some querying/parsing over this node and its children. Most operations of dojo.query (querying based on class, etc.) work properly. However, attempting to query based on id fails, as dojo.query uses dojo.byId (and therefore document.getElementById) to retrieve those elements.

If the purpose of dojo.query is to always fetch items relative to the provided root element, this is not the desired behavior. I've attached a sample test case, as well as a patch to dojo/_base/query.js which does find the appropriate element.

The source attached falls under the same CLA as Jared Jurkiewicz and Bill Keese.

Attachments

queryTest.html (0.7 kB) - added by guest 22 months ago.
test.html (71 bytes) - added by guest 22 months ago.
query.js.diff (1.7 kB) - added by guest 22 months ago.
query.js.2.diff (1.8 kB) - added by guest 22 months ago.

Change History

Changed 22 months ago by guest

Changed 22 months ago by guest

Changed 22 months ago by guest

Changed 22 months ago by guest

Changed 22 months ago by guest

Another possible solution to this bug is allowing the caller to provide a function for finding elements based on ID, passed as an optional argument to dojo.query, like so:

function myById(id, root){
    //...Do Stuff...
    return node;
}
dojo.query("testId", div, myById);

This would obviously be a small API change by adding in an optional argument to dojo.query, but it would take the extra code (size and performance) out of core and require the developer to account for this (not-so-)special case of addressing DOM elements that aren't in the current document.

Changed 21 months ago by peller

  • owner changed from anonymous to alex

Changed 17 months ago by dylan

  • summary changed from Query doesn't handle queries by ID relative to a root node properly to [patch][ccla] Query doesn't handle queries by ID relative to a root node properly
  • milestone set to 1.1

Changed 16 months ago by bill

  • milestone changed from 1.1 to 1.2

Move all milestone 1.1 tickets to 1.2, except for reopened tickets and tickets opened after 1.1RC1 was released.

Changed 11 months ago by dmachi

  • type changed from defect to enhancement
  • description modified (diff)

Changed 11 months ago by alex

  • type changed from enhancement to defect

hrm, I think this really is a defect. It's a spec violation.

Changed 11 months ago by alex

  • status changed from new to assigned

Changed 11 months ago by liucougar

btw, this works as expected:

dojo.query('*[id="search_id"]',your_root_node)

Changed 10 months ago by bill

  • milestone changed from 1.2 to 1.3

as per today's meeting, punting these core bugs

Changed 7 months ago by bill

  • milestone changed from 1.3 to future

Changed 6 months ago by alex

(In [16218]) some require() and NodeList? doc changes that happened while I was hacking on steak. Refs #7072, #4425

Changed 6 months ago by alex

(In [16226]) steak -> acme. Need a better name. Refs #7072. Refs #4425. !strict

Changed 6 months ago by alex

(In [16228]) updating for the acme engine. Refs #7072. Refs #4425

Changed 6 months ago by alex

(In [16232]) some size reductions. Also (finally) enables the QSA branch. Not sure how I missed that.

Refs #7072. Refs #4425. !strict

Changed 3 months ago by alex

  • status changed from assigned to closed
  • resolution set to fixed
  • milestone changed from future to 1.3
Note: See TracTickets for help on using tickets.