Is there a way to clone a hierarchy of widgets. Say I have a form template that’s already been created. Can I clone it for re-use?
The alternative is to invoke a function that creates the hierarchy each time. I’m just considering alternatives.
Is there a way to clone a hierarchy of widgets. Say I have a form template that’s already been created. Can I clone it for re-use?
The alternative is to invoke a function that creates the hierarchy each time. I’m just considering alternatives.
This is a somewhat tricky area. In some cases, passing the same Object instance as a constructor block to multiple create() calls, will work because internally, we make a shallow copy. So, for example, this would work (note that you can pass as many Object instances to create() as you want, and they’ll overlay):
var genericButtonProps = {styleName: "foo"};
isc.Button.create(genericButtonProps, {title: "zoo"});
isc.Button.create(genericButtonProps, {title: "bar"});
But this is not safe:
var genericFormProps = {
styleName: "foo",
fields: [
{name:"field1", title: "My Field"},
{name:"field2", title: "My Other Field"}
]
};
isc.DynamicForm.create(genericFormProps, {ID: "firstForm"});
isc.DynamicForm.create(genericFormProps, {ID: "secondForm"});
The reason, as you’ve probably guessed, is that create() makes a shallow copy of the constructor properties and as a result the two forms above will share the exact same instance of the fields array. This may work for some cases, but can cause strange behavior in others, because each form assumes its instance of the fields array is unique.
SmartClient adds some handy methods to Array, including duplicate() which can help here and in the next release we’ll actually be providing a deep copy method for collections, which is probably what you want.
Another approach may be to deliver your cloneable constructor blocks as a string and use the browser’s native eval() call to instantiate the live constructor block for create().
What’s your use case here? I may be able to suggest a better approach, and in any case it will help us evaluate whether we should add enhancements in this area in the future. Thanks.
Two use cases.
I’m close to having this logic reduced to one or two lines of code which could be embedded in a function easy enough, though my ultimate goal is to define the pattern that works across multiple schema domains without having to hardwire functions for each case.
BTW, this weekend I had a vision of the Tab layout operating like a horizontal accordian. It would collapse dependant tabs when I went from one module to another. Say my tabs read:
Projects | Project 1 | Project 2 | Courtesy Patrol | … |
and I hit the Courtesy Patrol tab, then it would read:
Projects | … | Courtesy Patrol | Incident 1 | Incident 2
…just a thought, no commitment yet.
My ultimate goal: an interface where I can open an XSchema definition and have a new module instantiated and configured to use the definition based upon this overall CRUD pattern. The interface gives me the ability to redefine Titles, re-order the presentation, and save the configuration as a user preference (or publish for public consumption). The format of this configuration is simple decoration to the original SchemaSet.