Yes, my assumption was incorrect. I thought ajax() would return a Row 
object to my ID target element, so then I could use it within the element.

"I have never been so wrong".

Well, it works now:

controller:

def rank():

    ranks = db(db.rank.department_id == 
request.vars.department).select(db.rank.id, db.rank.name, 
orderby=db.rank.name)

    result = ""

    for r in ranks:
        result += "<option value='" + str(r.id) + "'>" + r.name + 
"</option>"

    return XML(result)

view:

<select class="generic-widget" id="seafarer_experience_rank" name="rank">
    {{if request.vars.department:}}
        {{=XML(result)}}
    {{pass}}
</select>

- it did the trick. The rest of the code is the same.

Cheers.


On Tuesday, June 18, 2013 8:37:00 PM UTC+2, Derek wrote:
>
> One more thing - I've seen people have issues with this time and again on 
> this list. You aren't the first person to think of doing this. Look for a 
> good recipe on web2pyslices which does what you want. There are quite a few.
>
>
> http://www.web2pyslices.com/slice/show/1467/cascading-drop-down-lists-with-ajax
>
>
> On Tuesday, June 18, 2013 10:39:51 AM UTC-7, lesssugar wrote:
>>
>> I'm building a cascading dropdown lists. I use web2py ajax function to do 
>> it. My code:
>>
>> select 1 (parent):
>>
>> <select class="generic-widget" id="seafarer_experience_department" 
>> name="department" 
>> onchange="jQuery('#seafarer_experience_rank__row').show('fast');ajax('rank', 
>> ['department'], 'seafarer_experience_rank');">
>>     {{=OPTION('-- Choose department --', _value="")}}
>>     {{for d in departments:}}
>>         {{=OPTION(d.name, _value=d.id)}}
>>     {{pass}}
>> </select>
>>
>> select 2 (child):
>>
>> <select class="generic-widget" id="seafarer_experience_rank" name="rank">
>>     {{if request.vars.department:}}
>>         {{for r in ranks:}}
>>             {{=OPTION(r.name, _value=r.id)}}
>>         {{pass}}
>>     {{pass}}
>> </select>
>>
>> controller function:
>>
>> def rank():
>>
>>     ranks = db(db.rank.department_id == request.vars.department).select(
>> db.rank.id, db.rank.name, orderby=db.rank.name)
>>
>>     return ranks
>>
>> Ajax function calls *rank *function and passess value of the currently 
>> selected option in *department *select (parent). Then, the function 
>> assigns DAL query to *ranks *and returns it.
>>
>> The thing is that *ranks *is a string when returned and the FOR loop in 
>> the select 2 is ommited. An example result code of the select 2 looks like 
>> this after ajax function's done it's job:
>>
>> <select class="generic-widget" id="seafarer_experience_rank" name="rank">
>> "rank.idrank.name137Chief Cook138Chief Steward139Cook 
>> Assistant140Messman136Second Cook141Steward"
>> </select>
>>
>> So it LOOKS like a Row object but it's a string obvioulsy - and I can't 
>> get any Row data out of it (r.name, r.id).
>>
>> Begging for help here :)
>>
>>  
>>
>>

-- 

--- 
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 [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to