Hi!
Here is my solution. I have modal_wrapper function. In controller file, I
have two controllers - main_page and modal_content:
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 3
def 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
On Thursday, February 11, 2016 at 8:07:32 PM UTC+3, [email protected]
wrote:
>
> Thank you for your answer Massimo. When I implemented this.
>
> <button onclick='window.open("{{=URL("my_view",args=something.id)}}",
> "mywindow");'>Apply To This Post</button>
>
> It shows me a button and then I get redirected to another page. I just
> wanted a pop up window open up with a form to submit that user can move
> around without being redirected to another page.
>
>
>
>
>
> On Wednesday, February 10, 2016 at 10:51:11 PM UTC-5, Massimo Di Pierro
> wrote:
>>
>> I see you want a different window, not a modal.
>>
>> then you have to put the form logic in its own controller action and call
>> it from js
>>
>> <button onclick="window.open("{{=URL('form_action)}}");">click
>> me</button>
>>
>> On Wednesday, 10 February 2016 18:00:44 UTC-6, [email protected]
>> wrote:
>>>
>>> Thank you for the answer Massimo. I did this like you said to put the
>>> form in the body in index/popup.html however, it didn't pop up like the
>>> example in the link above. Instead I got it in the same browser. I am
>>> guessing my implementation is wrong.
>>>
>>> <div class="modal fade">
>>> <div class="modal-dialog">
>>> <div class="modal-content">
>>> <div class="modal-header">
>>> <button type="button" class="close" data-dismiss="modal"
>>> aria-hidden="true">×</button>
>>> <h4 class="modal-title">Modal title</h4>
>>> </div>
>>> <div class="modal-body">
>>>
>>> {{=form}}
>>>
>>> </div>
>>> <div class="modal-footer">
>>> <button type="button" class="btn btn-default"
>>> data-dismiss="modal">Close</button>
>>> <button type="button" class="btn btn-primary">Save
>>> changes</button>
>>> </div>
>>> </div><!-- /.modal-content -->
>>> </div><!-- /.modal-dialog -->
>>> </div><!-- /.modal -->
>>>
>>>
>>>
>>>
>>> On Wednesday, February 10, 2016 at 5:06:28 PM UTC-5, Massimo Di Pierro
>>> wrote:
>>>>
>>>> Bootstrap3 has built-int modals:
>>>> https://nakupanda.github.io/bootstrap3-dialog/
>>>> You can but {{=form}} in the body of the modal.
>>>>
>>>> On Tuesday, 9 February 2016 14:26:05 UTC-6, [email protected] wrote:
>>>>>
>>>>> Hello, A new user migrating from Django to web2py and absolutely
>>>>> loving it. A quick question. How do I use a light box or a pop up window
>>>>> to
>>>>> display a form in my view?
>>>>>
>>>>>
>>>>> for example in default/index.html
>>>>>
>>>>> {{=form}}
>>>>>
>>>>> Want to show that form in a pop up window.
>>>>>
>>>>
--
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.