Yes! Of course! Because there is a small bug in web2py.js in ajax() (or
in the manual) :
If middle arg ( '[ ]' ) is string, it's treated as JQuery selector
without any processing!
So ajax() call must be like:
ajax('{{=URL('default','get_options_for_dropdown2')}}', '[name="sel_1"],
[name="sel_2"]', 'dropdown2')
On Wednesday, August 12, 2015 at 10:46:08 AM UTC+3, Gael Princivalle wrote:
>
> Thanks a lot Val that's certainly the solution, however in the controller
> the var is always empty.
> This is the original select code:
> <select name='ceo_scheme' onchange="$('#overrides').empty(); ajax(
> '{{=URL('default','get_options_for_overrides')}}', ['ceo_scheme'],
> 'overrides');">
>
> If I set manually the var in get_options_for_overrides the ajax call works.
> For debug, if I modify get_options_for_overrides for
> returning get_options_for_overrides.vars.ceo_scheme the target select
> 'override' is empty.
>
> My original controller:
> def get_options_for_overrides():
> ceo_scheme_id = get_options_for_overrides.vars.ceo_scheme
> overrides = db(db.ceo_schemes_and_overrides.ceo_scheme ==
> ceo_scheme_id).select(db.ceo_schemes_and_overrides.ALL)
> html = ''
> for override in overrides:
> html += '<option value=' + str(override.override.id) + '>' +
> override.override.name + '</option>' + '\r\n'
> return html
>
> My controller for debug:
> def get_options_for_overrides():
> ceo_scheme_id = get_options_for_overrides.vars.ceo_scheme
> return ceo_scheme_id
>
> Do you know why?
>
> Regards.
>
> Il giorno martedì 11 agosto 2015 22:32:06 UTC+2, Val K ha scritto:
>>
>> Hello.
>> Keep in mind that ajax() - is a simple web2py function which is based on
>> Jquery (see web2py.js , its code is very short and clear)
>> It can pass to controller the values of the input elements only, see
>> http://api.jquery.com/serialize/.
>> So your select controls must have a name
>> - <select name="any_name_1" ...
>>
>> To pass its values just include its names in [' '] - ajax('{{=URL('
>> default','get_options_for_dropdown2')}}', ['any_name_1, any_name_2, ...'
>> ], 'dropdown2');">
>> To get it in the controller:
>> get_options_for_dropdown2.vars.any_name_1
>>
>>
>>
>> On Tuesday, August 11, 2015 at 6:43:59 PM UTC+3, Gael Princivalle wrote:
>>>
>>> Hello.
>>>
>>> I'm still making a form like in this post:
>>>
>>> https://groups.google.com/forum/#!searchin/web2py/jquery$20db/web2py/tvfncYsLrQs/MRHG5MWOMlAJ
>>>
>>> <!-- DROPDOWN1-->
>>> <select onchange="jQuery('#dropdown2').empty(); ajax('{{=URL('default','
>>> get_options_for_dropdown2')}}', [''], 'dropdown2');">
>>> <option...
>>> </select>
>>> <span id='dropdown2'>
>>> <!-- DROPDOWN2-->
>>> <select id='dropdown2'>
>>> <option...
>>> </select>
>>>
>>> How is it possible to pass like a var the current select option value to
>>> the ajax call?
>>>
>>> With something like that?
>>> data: {value: $('#select option:selected').val()}
>>>
>>> How it will be possible to retrieve this in the controller?
>>>
>>> Thanks.
>>>
>>
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
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/d/optout.