Dojo.parser.parse only works the first time it is called

I have a page where when a user clicks on a link to some reporting tools, it first prompts them for some report parameters. I am getting the options dialog as a form using AJAX, based on the link id. Each dialog has several dojo controls, so I need to parse them when the dialog pops up because it is not part of the page.

The first dialog box when the callee works fine, but subsequent calls to the dialog boxes fail to parse the dojo controls.

Example:

 showParametersDialog : function(doc) {
     var content = doc.firstChild.firstChild.data;
     var container = document.createElement('div');
     container.id = 'dialog';
     container.innerHTML = content;
     container.style.background = 'transparent';
     container.style.position = 'absolute';
     container.style.top = (document.body.clientHeight / 2) - 124 + "px";
     container.style.left = (document.body.clientWidth / 2) - 133 + "px";
     container.style.display = 'block';
     document.body.appendChild(container);

     // set up date fields
     var date_from = dojo.byId('date_from');
     var date_to = dojo.byId('date_to');
     try {
      date_from.value = dojo.date.locale.format(new Date(), {selector: 'date'});
      date_to.value = dojo.date.locale.format(new Date(), {selector: 'date'});
     } catch(e) {
      var now = new Date();
      date_from.value = String(now.getMonth() + "/" + now.getDate() + "/" + now.getFullYear());
      date_to.value = String(now.getMonth() + "/" + now.getDate() + "/" + now.getFullYear());
     }
     dojo.parser.parse();
    }

      

All dialogs have common date fields. So when I call this dialog for the first time and dojo.parser.parse () is called, it parses the controls in the dialog, but only the first time ... after, not dojo.

Any thoughts?

Thank you Paul.

+2


source to share


3 answers


you can use

dojo.parser.instantiate([dojo.byId("myDiv")]);

      

instead of dojo.parser.parse (); Use it on all non-parameterized objects.



You can find more details about this here:

http://livedocs.dojotoolkit.org/dojo/parser

+1


source


it's not that it doesn't parse the second time, it's that if the dojo tries to parse something more than once, it fails. You can track with a boolean flag if it has already been parsed, and if not, skip the line that parses it.



if (!parsed)
{
    dojo.parser.parse();
}

      

0


source


Perhaps this is because you are missing something of the type dojo.parser.parse(container)

. Otherwise, it will probably try to parse the entire document and find the parsed elements and stop.

(wild guess, learned from old dojo lore)

0


source







All Articles