Opened 12 years ago

Closed 8 years ago

#3849 closed defect (wontfix)

dojo.query does not work on imported nodes

Reported by: guest Owned by: Kris Zyp
Priority: low Milestone: future
Component: Query Version: 0.9
Keywords: Cc: keithpk@…
Blocked By: Blocking:

Description (last modified by bill)

  • Version: 0.9beta
  • Browsers: FF 2.0 (probably more)
  • Contact: keithpk at gmail dot com
  • Note: The issue was posted in the forums, and no one has responded, so I'm filing a ticket.
  • Description: In short, if you use import node to import some html from another document dojo.query can not find those nodes. The standard document.getElementById can though, so I'm not sure where the bug is. I have written a simple test case to reproduce this, which uses dojo.parser to show that the parser can not find/query for the inserted node. When you run this test, you will see that the first two buttons parse fine, the 3rd button, however, does not. Note: it will only work on FF, as DOMParser is not supported in IE.
<html>
  <head>
    <title>Dojo: Hello World!</title>
   
    <link rel="stylesheet" type="text/css" href="js/dojo/dijit/themes/tundra/tundra.css"/>
    <script type="text/javascript" src="js/dojo/dojo/dojo.js" djConfig="parseOnLoad: true">
    </script>
    <script type="text/javascript">

       dojo.require("dijit.form.Button");
        dojo.require("dojo.parser");

        function onPageLoad()
        {
            // Create a separate document
             var text = "<doc xmlns="http://www.w3.org/1999/xhtml"><button dojoType="dijit.form.Button" id="test3">Test3</button></doc>";
            var parser = new DOMParser();
            var doc = parser.parseFromString(text, "text/xml");

            // Get the button from the document
            var button_element = doc.getElementById("test3");

            // Import the button node into our document
            var import_button = document.importNode(button_element, true);
           
            // Insert it into our document   
            var dom_insert_node = document.getElementById("dominsert");
            dom_insert_node.appendChild(import_button);   
 
            // The parser can not find it    
            dojo.parser.parse();

            // Look it up in the document. Get element by id can find it just fine
            var lookup = document.getElementById("test3");
               
            // Choose your output method
            console.log(lookup);
            //alert(lookup);
        }
    </script>
  </head>

  <body onload="onPageLoad()">

    <button dojoType="dijit.form.Button" id="test1">Test1</button>
    <div>
        <button dojoType="dijit.form.Button" id="test2">Test2</button>
    </div>
    <div id="dominsert">
    </div>
  </body>
</html>

Attachments (1)

ff.html (1.7 KB) - added by bill 8 years ago.
test case, still fails on FF11 (button3 not turned into widget)

Download all attachments as: .zip

Change History (13)

comment:1 Changed 12 years ago by bill

Milestone: 1.1
Owner: changed from anonymous to alex

comment:2 Changed 12 years ago by dylan

Milestone: 1.11.2
Summary: dojo.qery does not work on imported nodesdojo.query does not work on imported nodes

comment:3 Changed 12 years ago by alex

Status: newassigned

this is really funky. It seems that the xpath back-end to dojo.query() isn't correctly finding non-standard attributes on imported nodes whereas the non-xpath back-end will correctly find them.

I don't have a solution (looks like a Mozilla bug and it's still present in FF3b3), but the workaround here is to specify innerHTML on a container after using the dojox XML DOM serialization function:

http://redesign.dojotoolkit.org/jsdoc/dojox/HEAD/dojox.data.dom.innerXML

Regards

comment:4 Changed 11 years ago by bill

Milestone: 1.21.3

as per today's meeting, punting these core bugs

comment:5 Changed 11 years ago by bill

Description: modified (diff)
Milestone: 1.3future

comment:6 Changed 10 years ago by bill

Component: CoreQuery

comment:7 Changed 8 years ago by Chris Mitchell

Owner: alex deleted
Status: assignednew

comment:8 Changed 8 years ago by Chris Mitchell

Owner: set to dylan

comment:9 Changed 8 years ago by dylan

Owner: changed from dylan to kriszyp

comment:10 Changed 8 years ago by bill

Owner: changed from kriszyp to Kris Zyp

comment:11 Changed 8 years ago by ben hockey

Keywords: needsreview added
Priority: highlow

this sounds like a browser bug. Should it be closed as wontfix?

comment:12 Changed 8 years ago by bill

Description: modified (diff)
Keywords: needsreview removed
Resolution: wontfix
Status: newclosed

I think so. Unfortunately the bug still happens even in FF11, but I don't think it's worth trying to workaround in dojo code (and also don't know how). Plus Alex gave a workaround that users can use.

Changed 8 years ago by bill

Attachment: ff.html added

test case, still fails on FF11 (button3 not turned into widget)

Note: See TracTickets for help on using tickets.