:: Forum >>
Trouble creating compound controls
I am trying ot create a control that is made up of other controls and I thought I would start simple and work my way up. This is what I have but when I write the control to the page, I just get the main DIV with no 'internal' controls. I know I am missing something simple, what is it?
Here is my test control:
AW.HTML.DispatchTool = AW.System.Template.subclass();
AW.HTML.DispatchTool.create = function()
{
var obj = this.prototype;
obj.setTag('DIV');
obj.defineTemplate("DispatchHeader", new AW.System.Template);
with (obj.getTemplate("DispatchHeader"))
{
setTag('DIV');
setStyle("height", 50);
setStyle("position", "absolute");
setStyle("width", "100%");
setStyle("background-color", "yellow");
}
obj.defineTemplate("AuxTop", new AW.System.Template);
obj.defineTemplate("GridBody", new AW.System.Template);
obj.defineTemplate("AuxBottom", new AW.System.Template);
obj.defineTemplate("TabBody", new AW.System.Template);
obj.defineTemplate("Tabs", new AW.System.Template);
obj.setContent(function() {
return
this.getDispatchHeaderTemplate() +
this.getAuxTopTemplate() +
this.getGridBodyTemplate() +
this.getAuxBottomTemplate() +
this.getTabBodyTemplate() +
this.getTabsTemplate();
})
}
AW.HTML.DispatchTool.create();
All assistance would be appreciated.
Jim Hunter
Wednesday, October 12, 2005
Jim,
here is the corrected code:
...
obj.setContent("html", function() {
return this.getDispatchHeaderTemplate() +
this.getAuxTopTemplate() +
this.getGridBodyTemplate() +
this.getAuxBottomTemplate() +
this.getTabBodyTemplate() +
this.getTabsTemplate();
})
}
Main problem was with return statement - it actually just returns nothing ignoring the next lines because it is equivalent to
return;
javascript treats end of line as end of statement (in most cases :-)
Couple of small other problems - calling create() method is no longer necessary - it will be called automatically during first constructor call (lazy class creation :-)
It is good idea to give a name to each content part. If you have only one - just call it 'html'.
Alex (ActiveWidgets)
Wednesday, October 12, 2005
Actually, the only issue was that I didn't have "html" in the setContent call. I moved the code up after the 'return' and it didn't make a difference, but once I added the "html" it works like I want. Now I need to test it with more then one of these controls on a page at a time. Last time I tried it, including methods in the control to change it's contents, changing one control updated the wrong one. It seemed to always change the most recent control created leaving the first one untouched. I will post back if I run into problems.
Thanks again Alex
Jim Hunter
Wednesday, October 12, 2005
This topic is archived.
Back to support forum
Forum search