Thanx Massimo for your response, again Sorry to ask for to much, for me as
a beginner would appreciate if u assisted with a full code eg:
Model: db.py
# table definitions as earlier given
Controller: default.py
def index():
form = SQLFORM.factory(db.address)
return dict(form=form)
View: index.html
{{=form}}
Problem I hv is how to get the fields from the town and province fields to
be part of the address form. Secondly how the view will look like
incorperating the Ajax code you had suggested. Where is it defined.
Teddy L
On Oct 30, 2012 8:36 PM, "Massimo Di Pierro" <[email protected]>
wrote:
> The problem is that you cannot have a
>
> Select Town: <List of Towns filtered from province>
>
> before you select a province. This means it cannot be serverside job. Not
> only.
>
> You need to handle it via ajax:
>
> var t = jQuery('input[name=province]');
> t.change(function(){jQuery.ajax({url:'{{=URL('towns')}}',data:{'province':t.value()},success:function(data)
> jQuery('select[name=town]').html(data); }) })
>
> and serverside:
>
> def towns():
> return CAT(*[OPTIONS(t.name) for t in
> db(db.town.province_id==db.province(request,vars.province)).select()])
>
>
> On Tuesday, 30 October 2012 12:27:26 UTC-5, software.ted wrote:
>>
>> Dear All,
>>
>> I am newbie to web2py have challenges but have more to lose if i
>> quite...so soldering on.
>>
>> I have a problem getting/understanding how drop down field work,
>> example are a bit difficult to follow, this is my situation and
>> tables:
>>
>> db.define_table('province', Field('name'))
>> db.define_table('town', Field('name'), Field('province_id',db.**province))
>>
>> db.define_table('address', Field('street'), Field('town_id', db.town))
>>
>> Now I need a form which which has the following field to update
>> "address" table in the database as follows:
>>
>> Select Province: <List of Province>
>> Select Town: <List of Towns filtered from province>
>> Enter street address: <Text file to enter an address>
>> <save button>
>>
>>
>> How does the controller look like?
>>
>> Teddy L.
>>
>> --
>> ..............................**..............................**...........................
>>
>> Teddy Lubasi Nyambe
>> Opensource Zambia
>> Lusaka, ZAMBIA
>>
>> Cell: +260 97 7760473
>> website: http://www.opensource.org.zm
>>
>> ~/
>> Human Knowledge belongs to the world! - AntiTrust
>>
>> Man is a tool-using animal. Without tools he is nothing, with tools he
>> is all - Thomas Carlyle 1795-1881
>>
>> /~
>>
> --
>
>
>
>
--