def main_page():
main_pg=DIV(<any your content>)
m_cont = LOAD(f='modal_content.load', ajax=True, ajax_trap=True )
dialog = modal_wrapper(m_cont, _id='cont_id', header='Header', footer='footer')
show_modal_btn = BUTTON( 'Show modal',
_type="button",
_class = "btn btn-default",
_onclick=""" $('#cont_id').modal('show') """)
#don't forget to add dialog and show_modal_btn to main page
main_pg.append(show_modal_btn) # or main_pg.append( DIV(show_modal_btn) ) or something else
main_pg.append(dialog)
return dict(main_pg = main_pg)
# keep in mind just one thing:
# this controller is exposed by *.load, so it must return a dict of ONE element
# to return more than one element - wrap all in one DIV:
# ret = DIV()
# ret.append( ... ) # ret.append( form )
# ret.append( ... )
# return dict(ret = ret)
def modal_content():
form = SQLFORM(...) # or even form = SQLFORM.grid(...)
return dict(form=form)
# means bootstrap 3def modal_wrapper(content, _id, header='', footer=''):
main_wrap = DIV('', _class="modal fade", _role="dialog", _id=_id, _tabindex="-1" ) title_id = _id + '_title' main_wrap['_aria-labelledby']=title_id
dialog_div=DIV('', _class="modal-dialog" , _role="document") content_div=DIV('', _class="modal-content") header_div = DIV( _class="modal-header")
close_cross = BUTTON( SPAN(XML('×'), **{'_aria-hidden':"true"}), _type="button", _class="close", data={'dismiss':"modal"}, **{'_aria-label':"Close"} ) title_h4 = H4( header, _class="modal-title", _id = title_id) body_div = DIV( content, _class="modal-body")
close_btn = BUTTON('Close', _type="button", _class="btn btn-default", data={'dismiss':"modal"}) footer_div = DIV( footer, close_btn, _class="modal-footer")
# gluon all main_wrap[0] = dialog_div dialog_div[0] = content_div
header_div.append(close_cross) header_div.append(title_h4)
[content_div.append(c) for c in (header_div, body_div, footer_div)] return main_wrap
def modal_content():
arg_0 = request.args(0)
a = request.vars.a
def main_page():
main_pg=DIV(<any your content>)
m_cont = LOAD(f='modal_content.load', args=[ <list of your args>], vars={<dict of your vars> }, ajax=True, ajax_trap=True )
...
def main_page():
main_pg=DIV(<any your content>)
m_cont = LOAD(f='modal_content.load', args=[1], ajax=True, ajax_trap=True ) # - must works, I'm sure while modal_content() runs "int(request.args(0)) == 1" will be true
...
What I have done with your code is change the contoller to be:
--
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 a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/Y_TXPdRpDqQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
So, I need to pass that argument from my view to the controller of the form. Only thing I have at my disposal is the button. I guess I just need to figure out how to pass the argument id into main_page(). Sorry, I am kind of new into this. So you have to excuse my ignorance.
Works fine. Because I see the button and I click and see the pop up. Great. Only issue is, I need to update the table with my argument. For example:
[...]
So, I need to pass that argument from my view to the controller of the form. Only thing I have at my disposal is the button.
from gluon.html import *
2. In view place:What I mean by passing argument from the view to the controller is this (let us consider in my view):
(1) <td width="40%"><a href="{{=URL('my_controler_def',args=id)}}">Apply</a></td>(2) <button onclick='window.open("{{=URL("my_controler_def",args=id)}}", "mywindow");'>Apply</button>In the above (1) is calling that URL with an argument id. (2) is a button, when I click on that, it goes to the controller function my_controler_def, and in my_controler_def I will have that "id" argument passed on.
default/main_page.html", line 83, in <module>
NameError: name 'modal_wrapper' is not defined
Controller is now:
def main_page():
main_pg=DIV('hello world')
#m_cont = LOAD(f='modal_content.load', ajax=True, ajax_trap=True )
#dialog = modal_wrapper(m_cont, _id='cont_id', header='Header', footer='footer')
show_modal_btn = BUTTON( 'Show modal',_type="button",_class = "btn btn-default",_onclick=""" $('#cont_id').modal('show') """)
#don't forget to add dialog and show_modal_btn to main page
main_pg.append(show_modal_btn) # or main_pg.append( DIV(show_modal_btn) ) or something else
#main_pg.append(dialog)
return dict(main_pg = main_pg)
View is:{{extend 'layout.html'}}
{{from gluon.html import *}}
{{=main_pg}}
{{id = 1}}
{{=modal_wrapper(LOAD(f='modal_content.load', args=id, ajax=True, ajax_trap=True ) , _id='cont_id', header='Header', footer='footer') }}