I would like to load different web2py components in the same view, but not at the same time. I have 5 .load files which have form fields for a different scenario, these are called dynamically by an onchange select script. Is it possible with web2py to do this?
Asked
Active
Viewed 1,209 times
1 Answers
3
Yes, but in that case, don't use the LOAD()
helper in the web2py view, as that will generate Javascript that loads the component immediately upon page load. Instead, create a div with an id to hold the component, and have your onchange
event handler call the web2py_component()
function with the id of the div as the target:
<div id='mycomponent'></div>
<script>
$(function() {
$('some_selector').change(function() {
web2py_component('{{=URL('default', 'mycomponent')}}', target='mycomponent');
});
});
</script>

Anthony
- 25,466
- 3
- 28
- 57
-
thanks, I figured it out. It's working now. 1 one more question does each .load file have to have a function named after it in the controller, cause mine does not work when i remove those functions. – samaras Jan 16 '13 at 05:31
-
1The .load files are just views -- they do nothing on their own. Like any action, components require a controller function. When the function returns, its associated view (i.e., the .load file) is executed. Note, component view files need not have a .load extension. That is just a convention. It can be useful when a component redirects, as the .load extension will be passed on in the redirect. – Anthony Feb 19 '13 at 05:09