If you are using SQLFORM to generate the form, one option is to manipulate
the form DOM after it has been created:
form = SQLFORM(...)
[op.update(_class='repeated') for op in
form.elements('select[name=event_class_id]
option')
if op['_value'] and db.event_class(op['_value']).repeated]
form.elements('select[name=event_class_id] option') returns a list of all
the option elements within the event_class_id select, and the list
comprehension updates the _class attribute if the value stored in the
option element is associated with an event_class record with a True value
in the "repeated" field. Warning: that will do a db query for each option
in the list.
Another option would be to create a custom widget for the field. You can
base it on the
OptionsWidget<https://code.google.com/p/web2py/source/browse/gluon/sqlhtml.py#224>.
You can subclass that class and replace the widget method.
Anthony
On Friday, April 26, 2013 5:47:26 AM UTC-4, Domagoj Kovač wrote:
>
> Hi,
>
> i have a question. I have a IS_IN_DB validator.
> fields.append(Field("event_class_id", "reference event_class",
> required=True,
> requires=IS_IN_DB(db, 'event_class.id', '%(name)s'
> , zero=T("-- Odaberite --")),
> label=LABEL("Vrsta događaja", _for=
> "event_value_event_class_id")))
>
> In my event class i have a structure like:
> db.define_table('event_class',
> Field('name', 'string',
> required=True,
> requires=IS_NOT_EMPTY(),
> label=LABEL(T("Naziv"), _for="event_class_name")),
> Field('repeated', 'boolean',
> label=LABEL(T("Ponavljanje"), _for="event_repeated"
> )),
> )
>
> Repeated field is a field that tells me weather do display one field on a
> form. I want to have HTML like this.
> <select>
> <option value="1">Name</option>
> <option value="2">Name 2</option>
> <option value="3">Name 3</option>
> <option value="4" class="repeated">Name 4</option>
> <option value="5">Name 5</option>
> </select>
> so when users selects a value i can check if i need to display repeated
> field based on the class
>
> Is this possible somehow?
>
--
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.