What I have done with your code is change the contoller to be:
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)
And in my view I have (I am making an example here):
{{extend 'layout.html'}}
{{=main_pg}}
{{=BUTTON( 'Apply',_type="button",_class = "btn
btn-default",_onclick="$('#cont_id').modal('show')")}}
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:
def modal_content():
db.mytable.id.default = request.args(0) #Just an example.
form = SQLFORM(db.mytable) # or even form = SQLFORM.grid(...)
return dict(form=form)
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.
On Friday, February 12, 2016 at 2:25:36 PM UTC-5, Val K wrote:
>
>
> I mean passing args/vars in main_page():
>
> 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 )
> ...
>
>
>
> But may be you want to pass something from client side, i.e. args are
> defined by some user action.
> What exactly do you want to do?
>
>
>
>
>
> On Friday, February 12, 2016 at 10:00:22 PM UTC+3, [email protected]
> wrote:
>>
>> In the book it says load in the view. Nothing in the controller. I was
>> just wondering if we can add a button in the view and call the ajax from
>> the view with the argument. If we need to call the LOAD from the view, its
>>
>> {{=LOAD('default','manage_things',ajax=True)}}
>>
>> Then it fails for m_count.
>>
>>
>> On Friday, February 12, 2016 at 12:20:10 AM UTC-5, Val K wrote:
>>>
>>> LOAD() works like URL(), so, to pass args/vars to modal_content you
>>> could write
>>> m_cont = LOAD(f='*modal_content**.load*', *args=[ ], vars={ }*,
>>> ajax=True, ajax_trap=True ) # see LOAD in web2py book
>>>
>>> in modal_content controller there is nothing new, everything is as usual
>>>
>>> def modal_content():
>>> arg_0 = request.args(0)
>>> a = request.vars.a
>>>
>>>
>>>
>>> On Friday, February 12, 2016 at 1:16:35 AM UTC+3, [email protected]
>>> wrote:
>>>>
>>>> Thank you! Val and the app works great.
>>>>
>>>> One question:
>>>>
>>>> Instead of controller, I have the button displayed in the view as:
>>>>
>>>> {{=BUTTON( 'Apply',_type="button",_class = "btn
>>>> btn-default",_style="background-color:green;background-image:none",_onclick="""
>>>>
>>>> $('#cont_id').modal('show') """ )}}
>>>>
>>>> It works, however, I need to pass an argument to my controller
>>>> "modal_content". How do I pass a request.args(0) from my view to the
>>>> controller in above? Just like I would do
>>>>
>>>> <button onclick='window.open("{{=URL("*modal_content*",args=
>>>> something.id)}}", "mywindow");'>Apply</button>
>>>>
>>>>
>>>> Since I don't see the URL or callback to the javascript. Thanks in
>>>> advance.
>>>>
>>>>
>>>> On Thursday, February 11, 2016 at 4:27:22 PM UTC-5, Val K wrote:
>>>>>
>>>>> 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.