I'd like my gadget to have two different views: One when it's just been added, to let the user enter some information, and, once he's done with that, another which displays some data based on that information.
The earliest point at which I can decide which of those two views I have to display is when I get the state for the first time, i.e. in the state callback. When I change the UI there, however, it does not always show - apparently there are some timing issues involved. Sometimes the UI doesn't show up at all, sometimes it shows up ok, sometimes it shows up in front of the Gadget-loading animation.
Here's a simple test case:
<?xml version="1.0" encoding="UTF-8" ?>
<Module>
<ModulePrefs title="Trivial" height="120">
<Require feature="wave" />
</ModulePrefs>
<Content type="html">
<![CDATA[
<script type="text/javascript">
function createForm () {
document.write("<div id=\"form\">");
document.write("Username: <input type=text value=\"whatever\" id=\"user_name\">");
document.write("<input type=button value=\"Go!\" onClick=\"fetchFromUsername()\"><br>");
document.write("NSID: <input type=text value=\"287312604@N00\" id=\"user_id\">");
document.write("<input type=button value=\"Go!\" onClick=\"fetchFromNSID()\"><br>");
document.write("Number of photos: <input type=text value=\"3\" id=\"per_page\">");
document.write("</div>");
}
</script>
<script type="text/javascript">
function stateUpdated () {
createForm ();
}
function init() {
if (wave && wave.isInWaveContainer()) {
wave.setStateCallback (stateUpdated);
}
}
gadgets.util.registerOnLoadHandler(init);
</script>
]]>
</Content>
</Module>