Window is not fully built in afterShow

I have a window with a div:

dhxWindowObj.attachHTML("<div id='"divTest"' >test</div>");

I want to work with the div so I am trying to access it in this event

    dhxWindowObj.events.on("afterShow", function(id){                       
        $('#divTest').load(url);        
    });

but $(’#divTest’) is undefined in this event. Since there is no afterLoad event I assumed the window is fully built after it is shown but seems not to be the case - is this a bug or is there a missing event on the Window object?

Hello,
If you attach the event after the Window is displayed, it will fire only after you open the Window again:
After:
https://snippet.dhtmlx.com/m504ei9h
Before:
https://snippet.dhtmlx.com/enfomckj

If that doesn’t help you, please, reproduce the issue in the snippet, then click on the “Save” button and send me the link.

I am attaching the event before the show like this
https://snippet.dhtmlx.com/8monk3al
and this is when I get the error ie. I’m looking for an event similar to document ready but for the window object.

I have the same issue. I have a dhx Form attached to my window. I’m trying to set the focus to an input field when the window is shown.

win.events.on("AfterShow",function(){
    var el = document.getElementById("ClockNumber");
    el.focus();
});
// throws error, cannot access property of non-object... el is null

But…

win.events.on("AfterShow",function(){
    setTimeout(function(){
        var el = document.getElementById("ClockNumber");
        el.focus();
    },1000);
}
// works, but I don't feel I should have to use setTimeout if the event is "AfterShow"

Please, try to use the awaitRedraw function

dhxWindowObj.attachHTML("<div id='"divTest"' >test</div>");

dhxWindowObj.events.on("afterShow", function(id){ 
   dhx.awaitRedraw().then(() => {
      $('#divTest').load(url);     
   })                      
});
1 Like

That works just fine, thanks