Example (may need debugging)
#in model
db.define_table('cities',
SQLField('state'),
SQLField('city'))
db.define_table('person',
SQLField('name'),
SQLField('state'),
SQLField('city'))
db.person.state.requires=IS_IN_SET(db,'cities.state')
db.person.city.requires=IS_IN_SET(db(db.cities.state==request.vars.state),'cities.city')
#in controller
def index():
form=t2.create(db.person)
return dict(form=form)
def callback():
return ''.join([OPTION(r.city).xml() for r in
db(db.cities.state==request.vars.state))
#in view index.html
{{extend 'layout.html'}}
{{=form}}
<script>
$('#person_state').change(functions(){$.ajax({
type: "POST",
url: "{{=URL(r=request,f='callback')}}",
data: "state="+$('#cities_state').val(),
success: function(msg){ $('#person_city').html(msg);}
});
});
</script>
Explanation. Assuming cities is populated. When you change the state
it makes an ajax callback replaces the options of the city selector.
Massimo
On Oct 6, 2:28 am, Oscar <[EMAIL PROTECTED]> wrote:
> Hi Again,
>
> I'm exploring T2, and... there is a way to do a dynamic form, I mean,
> I have a dropdown STATE field populated from a db:
>
> db.define_table('cities',
> SQLField('state'),
> SQLField('city'))
>
> Then my form only shows State field at the view, but I want that when
> I select the state my forms shows the city field with respective
> cities for that state.
>
> I don't know if I must construct a entire form using view or there is
> an auto generated way ???
>
> Regards,
>
> Oscar.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"web2py Web Framework" 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
-~----------~----~----~----~------~----~------~--~---