On Fri, Jan 15, 2010 at 1:17 PM, Alexandre Andrade <[email protected]
> wrote:

> db.task.contact_id.requires=IS_NULL_OR(IS_IN_DB(db,'contact.id
> ','%(name)s'))
>
> do what you want
>

Not really. It works if there are already records in db.contact related to
the task. But in there aren't any I get the ValueError. Also note that if
there are contacts (not all the contacts just those that are related to the
account the task is being created to), I use this set in the view to
construct the select tag. There I include the empty option in the select tag
(as described elsewhere on this group).

Miguel




> 2010/1/15 Miguel Lopes <[email protected]>
>
>> I have a select field on a form. It might be empty or take one related
>> value.
>>
>> I the model:
>> db.task.contact_id.requires=IS_IN_DB(db,'contact.id','%(name)s')
>> db.task.contact_id.requires.zero=''
>>
>> In a custom form:
>> {{keys, values=[''],[0]
>> keys.extend([contact.name for contact in contacts])
>> values.extend([contact.id for contact in contacts])
>> items=zip(values,keys)}}
>> {{=SELECT([OPTION(k,_value=v) for (v,k) in items], _name="contact_id")}}
>>
>> This results in a form.errors of 'value not in database' for the
>> contact_id field.
>> I'm sure this is very trivial. But I'm haven't found a way of solving
>> this.
>>
>> Txs for the help,
>> Miguel
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "web2py-users" group.
>> To post to this group, send email to [email protected].
>> To unsubscribe from this group, send email to
>> [email protected]<web2py%[email protected]>
>> .
>> For more options, visit this group at
>> http://groups.google.com/group/web2py?hl=en.
>>
>>
>
>
> --
> Atenciosamente
>
> --
> =========================
> Alexandre Andrade
> Hipercenter.com
>
> --
> You received this message because you are subscribed to the Google Groups
> "web2py-users" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<web2py%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/web2py?hl=en.
>
>
--
You received this message because you are subscribed to the Google Groups "web2py-users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to [email protected].
For more options, visit this group at http://groups.google.com/group/web2py?hl=en.

Reply via email to