This is brilliant !!
Thanks a LOT Anthony

What I ended up doing is :

if request.args(0) == "edit":
    db.child.parent.requires = IS_IN_DB(.....)

In my actual setup - user does not create new record - so "new" is not an
issue *for me*.

-Mandar


On Thu, Jun 12, 2014 at 4:57 PM, Anthony <abasta...@gmail.com> wrote:

>
>  Are you saying you want the user to enter a last name for the child and
>>> then have the drop-down dynamically updated with the list of parents with
>>> the entered last name? If so, obviously that cannot be done at the time the
>>> form is generated on the server because you don't know what name the user
>>> will enter in the form.
>>>
>>
>> Hmm.. I did not thing of that.
>> Actually I was trying only "Edit" option - where last name of the child
>> is known, but parent information is not populated.
>> Did not think of "New" scenario - my bad.
>>>
>>>
> In the "edit" scenario, you do have the child last name, so you can take
> the approach I showed, though you have to set the validator after you
> retrieve the relevant record. So you would do something like:
>
> child_record = db.child([some id])
> db.child.parents.requires = IS_IN_DB(db(db.parent.lname = child_record.
> last_name), ...)
> edit_form = SQLFORM(db.child, record=child_record)
>
>
>> You'll instead have to handle this with Javascript in the browser,
>>> possibly with an Ajax call back to the server to populate the list
>>>
>>  (unless the list of parents is small enough to send to the browser with
>>> the initial page load).
>>>
>>
> Makes sense. In that case :
>>
>
> should I even use "reference parent" ? Cause I think it will automatically
>> create and populate the widget for me (which I think I will need to hide
>> somehow ?)
>>
>
> You still want it to be a reference field. If you don't want the default
> widget associated with the IS_IN_DB validator, you can always put it in a
> list (which suppresses the drop-down list widget):
>
>     Field('parents', 'list:reference parent', requires=[IS_IN_DB(...)])
>
> Anthony
>
>
> -Mandar
>
> --
> Resources:
> - http://web2py.com
> - http://web2py.com/book (Documentation)
> - http://github.com/web2py/web2py (Source code)
> - https://code.google.com/p/web2py/issues/list (Report Issues)
> ---
> You received this message because you are subscribed to a topic in the
> Google Groups "web2py-users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/web2py/nDBOL7w6qB4/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> web2py+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to