Thanks Anthony! using the option helper and returning without the 
dictionary solved my issue, there is other errors on the javascript but i 
already solved it, now works well, one more question: There is no built-in 
function that creates a dropdown list from a DAL select?

El viernes, 7 de agosto de 2015, 11:34:31 (UTC-4:30), Anthony escribió:
>
> If your function returns a dictionary, web2py assumes you want to execute 
> a view. If you haven't created a view, it will use generic.html (by 
> default, this only works for local requests). If you just want to return 
> the raw HTML generated in the controller without then executing a view, 
> then just return the HTML (i.e., no dictionary).
>
> Additionally, you might want to consider building the HTML using the 
> web2py HTML helpers rather than building it via strings. In that case, you 
> can just return the final HTML helper, and it will automatically be 
> converted to an HTML string before returning to the browser.
>
> If you do actually have a view that is being executed and you want to 
> insert raw HTML, you would wrap it in XML() (though, again, you could 
> instead just use the web2py HTML helpers and not bother with XML()).
>
> Anthony
>
> On Friday, August 7, 2015 at 11:50:47 AM UTC-4, Luis Valladares wrote:
>>
>> Hello!
>>
>> I've a form where i store country, state and municipality and i need to 
>> dynamcally change the value based on the select, i mean: If i select a X 
>> country i need to display only the states of the country "X" in the states 
>> dropdown, the same with municipality
>>
>> I used a basic approach that i've used many times befores in other 
>> languages, a jquery function on dropdown change that ajax call a page and 
>> it returns the options and put it into the dropdown, i've been researching 
>> and found this really helpful: 
>> http://stackoverflow.com/questions/10387672/web2py-dropdown-menu, so 
>> based on this answer i build this structure:
>>
>> On the controller: 
>>
>> def ajaxMunicipio():
>>     if request.args(0) in db.estados.id:
>>         response.generic_patterns = ['load']
>>         data = db(db.municipios.estado == request.args(0)).select()
>>         html = "\<select\>"
>>         for fila in data:
>>             html += "\<option value=\""+str(fila.id
>> )+"\"\>"+fila.nombre+"\</option\>"
>>         html += "\</select\>"
>>         return dict(form=html)
>>     else:
>>         raise HTTP(404)
>>
>>
>>
>>
>>
>> And on the view:
>>
>>   jQuery(function() {
>>     jQuery('#no_table_estado_id').change(function() {
>>       var request = $.ajax({
>>         url: "{{=URL('hot', 'ajaxMunicipio.load')}}" + "/" + 
>> jQuery(this).val(),
>>         method: "GET",
>>         dataType: "html"
>>     });    
>>       request.done(function(html) {
>>         console.log(html)
>>         $("#no_table_municipio_id").val(html);
>>       });
>>     })
>>   })
>>
>>
>>
>> everything works well on the call side but i recieve the HTML sanitized 
>> like this: \&lt;select\&gt;\&lt;option 
>> value=&quot;1&quot;\&gt;LIBERTADOR\&lt;/option\&gt;\&lt;/select\&gt;
>>
>> So i'm looking for a way to avoid web2py to sanitize the html, or maybe a 
>> cleanest way to do this because i dont really like looping the data in the 
>> controller in order to create the HTML
>>
>> I appreciate any help you can give! Thanks for your atention
>>
>>
>>

-- 
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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to