As I guess Massimo wanted to post these answers to the list and not only to me, I´ll forward his answers here.

On Jul 23, 10:19 am, Kenneth Lundström<[email protected]>
wrote:

I m creating a form with SQLFORM that includes 6 fields.

One field is f_customer with requires IS_IN_DB(....)

Now I'd like to add a new field not taken directly from database. Lets
call it f_extra.

f_customer is a drop-down and f_extra would also be a drop-down. Now I
have a list of questions.

1) Is it possible to get the form.accepts to validate that either
f_customer or f_extra is selected. Both can t be selected and both can t
be empty? I remember seeing this discussed on the list not long ago, but
could not find it.

2) If 1) is not possible then I guess I have to put dbio=False and do
the validation "manually". How do I show the error message the same way
web2py does?
yes

def check(form):
    if (form.vars.a and form.vars.b) or (not form.vars.a and not
form.vars.b):
        form.errors.b = "a and b cannot be both empty or selected"
form.accepts(...,onvalidation=lambda form: check(form))


3) Instead of creating a custom layout for this form I d like to add the
field in the controller with something like:
form.element('table').insert(2,TR('label',INPUT(_name='name'))), but how
do I add a SELECT with many OPTIONS? The f_extra field drop-down is
created from two different tables auth_user and t_extra_fields. I guess
I should use query auth_user and t_extra_fields and then create a list.
That list is used to create the drop-down.
Is this a FORM or  SQLFORM. In the latter case you need a custom
widget. In the former case you can do

SELECT(*[OPTION(value) for value in ....],**dict(value='default'))


4) When using the OPTION helper is it possible to have a different value
of the option then what is shown?
OPTION('shown value',_value='hidden value')




Reply via email to