Custom Widget disappearing when page is opened more than once

2
I created a custom widget with a custom function and called that function inside the update function update: function (obj, callback) { logger.debug(this.id + ".update"); this._customTable(); this._contextObj = obj; this._updateRendering(callback); }, _customTable: function CustomFunction() { //Code var divContainer = document.getElementById("customTableWidget"); divContainer.innerHTML = ""; divContainer.appendChild(table); } And I used it in the template html <div class="widgetname" data-dojo-attach-point="widgetBase"> <body> <p id="customTableWidget"></p> </body> </div> I used the widget in a page and when I go to the page I get the output But, when I click the page button again (the Blue-White Asterisk), the table vanishes. The table comes back if I go back to Home and come back. When I search for the tag, the tag is there but the tags created by the javascript is gone. I’m new to custom widgets and I just did this with basics taught in the learning path. Please help me solve this. Is there any code placement problems or any other?
asked
1 answers
0

Mendix does not cope well with setting innerHTML as empty once you rerender the javascript code. Could you try setting it with a ‘space’ or even some text and checking whether it works then?

It is also best practice to create the necessary HTML elements with a widget template HTML file, with something like:

<canvas id="widgetid" class="col-md-10"  data-dojo-attach-point="yourDiv"></canvas>

 Then, in the widget JS code you can target it with:

this.yourDiv.appendChild(otherDiv)

 

Also, what -if any- message can you see in the browser console once the container disappears?

answered