Ticket #3849 (assigned defect)

Opened 2 years ago

Last modified 7 months ago

dojo.query does not work on imported nodes

Reported by: guest Owned by: alex
Priority: normal Milestone: future
Component: Core Version: 0.9
Severity: normal Keywords:
Cc: keithpk@…

Description (last modified by bill) (diff)

  • 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>

Change History

Changed 2 years ago by bill

  • owner changed from anonymous to alex
  • milestone set to 1.1

Changed 16 months ago by dylan

  • summary changed from dojo.qery does not work on imported nodes to dojo.query does not work on imported nodes
  • milestone changed from 1.1 to 1.2

Changed 16 months ago by alex

  • status changed from new to assigned

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

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

  • description modified (diff)
  • milestone changed from 1.3 to future
Note: See TracTickets for help on using tickets.