Hello Dave,

here how I solved this problem:

-----------------------------------------------------
from turbogears import expose, widgets
from sicer.model import Regione, Provincia, session
from turbogears.widgets.forms import Form

class NoSubmitForm(Form):
    template = """
    <form xmlns:py="http://purl.org/kid/ns#";
        action="${action}"
        method="${method}">
        <div py:for="i, field in enumerate(fields)">
            <label class="fieldlabel" for="${field.field_id}" 
py:content="field.label" />
            <span py:replace="field.display(value_for(field), 
**params_for(field))" />
        </div>
    </form>
    """
def opt_regioni():
    return [ (rec.codice, unicode(rec)) for rec in 
session.query(Regione).select() ]

def opt_province(cod_regione):
    return [ (rec.codice, unicode(rec)) for rec in 
session.query(Provincia).select_by(cod_regione=cod_regione) ]

indexForm = NoSubmitForm(
    fields = [ widgets.SingleSelectField(name='cod_regione',
                                         label='Regione',
                                         options=opt_regioni,
                                         
attrs={'onchange':'form.submit()'}),
               widgets.SingleSelectField(name='cod_provincia',
                                         label='Provincia',
                                         options=[('','')]),
               ],
    action='index',
)

class Controller(object):
    @expose(template="kid:sicer.templates.comuni.select")
    def index(self, **data):
        form_params = dict(value=data)
        if data:
            form_params['options'] = 
{'cod_provincia':opt_province(data['cod_regione'])}
        else:
            form_params['attrs'] = {'cod_provincia':{'disabled':'disabled'}}
        return dict(indexForm=indexForm, form_params=form_params)
-----------------------------------------------------------------------------------

jo


Dave wrote:

>Hello,
>
>I'm currently looking to design an application in Turbogears but am
>getting hung up on one specific challenge - that's updating form fields
>conditionally based upon the selection of another form field.  For
>instance:
>
>In a form, you have two select fields, one for state and one for city.
>I want the city field to be populated with city names that are ONLY in
>the state selected, which would (presumably) be pulled from a database.
> I'd like to do it asynchronously versus posting the entire form and
>dealing with the whole page reloading.
>
>I've found a lot of different posts that resemble, but aren't very
>clear.  Based on what I'm reading, it sounds like I would have to do
>something in Javascript on the "onchange" event on the "state" input
>that sends an HTTP request, gets some result and then updates the DOM
>object, but I'm getting a little lost here.  Can anyone point me in the
>right direction?
>
>Thanks,
>
>DS
>
>
>>
>  
>


--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To post to this group, send email to turbogears@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to