deform: how to add fields to an initialized form?

15 views
Skip to first unread message

Robert Forkel

unread,
Mar 5, 2012, 11:13:37 AM3/5/12
to pylons-discuss
Hi,
i have the following Problem: I want to add fields to a form at
arbitrary positions after the form instance has been initialized (this
is intended as a configuration mechanism - a default form can be
manipulated by custom packages).
I didn't find a public API method to do this, but came up with the
following:

myform = Form(MySchema(), buttons=[])

node = SchemaNode(String(), name='new', description='well, new')

myform.schema.add(node)
myform.children.insert(1, Field(node, renderer=myform.renderer,
counter=myform.counter,
resource_registry=myform.default_resource_registry))

obviously, that's a bit of a hack, but wouldn't look too bad if placed
in a form method "insert_node" or something the like. How fragile
would this be, i.e. how likely is it, the API it relies on will
change?
regards,
robert

Mariano Mara

unread,
Mar 5, 2012, 11:21:50 AM3/5/12
to pylons-...@googlegroups.com

Check out the following discussion [1] to see if it's of help.

Regards

[1] https://groups.google.com/forum/#!topic/pylons-discuss/55FXAMkde4w

Robert Forkel

unread,
Mar 5, 2012, 11:44:21 AM3/5/12
to pylons-...@googlegroups.com
Thanx for the pointer. Regarding the schema, I think my approach is
ok. "add" is part of the public API of a SchemaNode, and order in the
schema doesn't matter. Order does only matter for the rendering of the
Form, so my question is more related to my messing with Form.children.
I also want to manipulate the already instantiated Form, so the

self.children = []
self.__dict__.update(kw)
for child in schema.children:
self.children.append(Field(child,
renderer=renderer,
counter=self.counter,
resource_registry=resource_registry,
**kw))

in Field.__init__ has already taken place (and so manipulating the
order in the schema doesn't help anymore). I guess my question boils
down to whether I can regard the "children" list on deform.Field as
public API.

> --
> You received this message because you are subscribed to the Google Groups "pylons-discuss" group.
> To post to this group, send email to pylons-...@googlegroups.com.
> To unsubscribe from this group, send email to pylons-discus...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en.
>

Reply all
Reply to author
Forward
0 new messages