tags:

views:

1041

answers:

2

I have a page that when a user clicks on a link for some reporting tools, it first asks them to enter some report parameters. I get the parameters dialog as a form using AJAX, based on the id of the link. Each dialog has some dojo controls on it, so I need to parse them when the dialog appears, because it is not originally part of the page.

The first dialog when called works fine, but subsequent calls to dialogs fails 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 the common date fields. So when I call this dialog the first time, and dojo.parser.parse() is called, it parses the controls on the dialog, but only the first time...after than, no dojo.

Any thoughts?

Thanks, Paul.

A: 

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

if (!parsed)
{
    dojo.parser.parse();
}
Brian Schroth
A: 

This might be because you're missing something like dojo.parser.parse(container). Otherwise, it probably tries to parse the entire document and finds parsed elements and stops.

(wild guess pulled from old dojo knowledge)

Glenn
Here is the issue I get still: When the dialog in removed from the DOM and then re-appended after clicking the link a second time, I get "Tried to register widget with id==date_from but that id is already registered". So how do I destroy the dojo node correctly so that I can reuse it?Thanks
There is a "destroy" function you need to call when you want to remove a widget and it's children.
Glenn
None of the answers on this question are conclusive. I can witness the same behavior. Except that it is some what more random than that.
sims