Addressing individual fields of a FormFieldRepeater

5 views
Skip to first unread message

Joseph Tate

unread,
Jul 15, 2008, 10:52:41 PM7/15/08
to ToscaWidgets-discuss
I have a TextField done up in a FormFieldRepeater. I'd like to be
able to set labels, or perhaps the classes, but I can't figure out how
to "address" them through the display() method. If I use an
interactive prompt on the form object, I can get to a single
(template?) field, but can't figure out how to reach the individual
repeated elements.

For example, I have this form:

MessageForm(TableForm):
class fields(WidgetsList):
description = FormFieldRepeater(widget=TextField(validator =
UnicodeString(not_empty = True)), repetitions = 1,
max_repetitions=5)

I was able to set the repetitions using .display(**{'.description':
{'repetitions': 3}}), but haven't been able to set anything but the
value on the description text fields. Are there instructions on how
to reference individual repetitions through a Repeater class?

What I really want is to have separate rows for these fields, instead
of clumping them together into one td. Then I want the label to come
from one attribute of the description object, the help_text from
another, etc.

Alberto Valverde

unread,
Jul 16, 2008, 11:50:10 AM7/16/08
to toscawidge...@googlegroups.com

>
> I have a TextField done up in a FormFieldRepeater. I'd like to be
> able to set labels, or perhaps the classes, but I can't figure out how
> to "address" them through the display() method. If I use an
> interactive prompt on the form object, I can get to a single
> (template?) field, but can't figure out how to reach the individual
> repeated elements.
>
> For example, I have this form:
>
> MessageForm(TableForm):
> class fields(WidgetsList):
> description = FormFieldRepeater(widget=TextField(validator =
> UnicodeString(not_empty = True)), repetitions = 1,
> max_repetitions=5)
>
> I was able to set the repetitions using .display(**{'.description':
> {'repetitions': 3}}), but haven't been able to set anything but the
> value on the description text fields. Are there instructions on how
> to reference individual repetitions through a Repeater class?

You should be able to pass them in a list:

{'repetitions':3, child_args:[{...}, {...}]}

You might also want to pass a generator that send the same options to
every repetition... err, nope, a generator won't work since TW does an
isinstance(args, list) :( I should fix this some time but for the moment
you could implement an object that inherits from list but returns the same
args on __getitem__, perhaps...

> What I really want is to have separate rows for these fields, instead
> of clumping them together into one td. Then I want the label to come
> from one attribute of the description object, the help_text from
> another, etc.

label and help text can only be set on widget __init__ time ATM. there's a
ticket somewhere in tw.forms trac asking for label overrideability, you
mght want to toss in the help_text suggestion in there too.

Alberto

Reply all
Reply to author
Forward
0 new messages