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
>
> /~
>
--