[web2py] LOAD component inside component

183 views
Skip to first unread message

Richard

unread,
Apr 13, 2015, 4:00:39 PM4/13/15
to web...@googlegroups.com
Hello,

I create a page with multiple components inside of it (the index page is basically an empty shell for the components)... But one of there is a form in one of the embed component which as a field with a widget that trigger modal form allowing to insert a value in another table and select this inserted value (something like SELECT_OR_ADD() would do). The problem is that my form embeded in the modal which the widget append to the page with LOAD() don't load... It hang on "loading..."

Any idea?

Is it even possible to trigger a LOAD inside a LOAD?

Thanks

Richard

Massimo Di Pierro

unread,
Apr 15, 2015, 9:36:59 AM4/15/15
to web...@googlegroups.com
Never tried. My guess is that 

jQuery.web2py.trap_form is not called for the inner forms.

If you call it manually using jQuery you can make it work.

But I would not. I would figure out how to use ractive.js instead.

Richard Vézina

unread,
Apr 15, 2015, 10:46:12 AM4/15/15
to web2py-users
Yes I should give it a real try, though I found usage example scarce after tutorial...

I need to improve my ractive skill

:)

Richard

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

Dmitry Ermolaev

unread,
Apr 19, 2015, 12:12:13 PM4/19/15
to web...@googlegroups.com
simple use *.html view - not *.load
and use URL for set controller/function in LOAD()

I not use same views - onlu generic.html by:

def load_func_2():
   h = CAT()
   h += LOAD(...)
...
return h

def load_func():
...
   h = CAT()
   h += LOAD(URL('contloller','load_func_2', args=[], vars={}), ....)
return dict(h =DIV(h, _class='row'))

понедельник, 13 апреля 2015 г., 23:00:39 UTC+3 пользователь Richard написал:

Dmitry Ermolaev

unread,
Apr 19, 2015, 12:54:31 PM4/19/15
to web...@googlegroups.com
# -*- coding: utf-8 -*-

AJ_FROM_SERVER = True
UPD_TIMEOUT = 6000

def reload_btn(s):
    return DIV(T('RELOAD'),
        _onclick = 'ajax("%s", [], "reload_tag")' % URL('aj_load2','reload'),
        _class='btn btn-info')

def reload():
    session.counter = (int(session.counter or 0)) + 1
    
    # reload component
    response.js =  "jQuery('#show_1').get(0).reload();"
    #response.js +=  "jQuery('#show_2').get(0).reload();"
    return CAT(
        request.now,' ',
        session.counter,
        SCRIPT('$("html,body").animate({"scrollTop":50},"slow");')
        )

def show2():
    
    session.show2 = (int(session.show2 or 0)) + 1
    h=CAT(
            SCRIPT("""
            if ( ! $('#show_2').is(':visible')) {
                $('#show_2').animate({ height: 'show' }, 1000);
            }
            """),
            H4('SHOW 2'),
            T('COUNTER 2'),': ',session.show2,
        )
    h += reload_btn(1)
    
    return h # not need any view


def show1():
    
    session.show1 = (int(session.show1 or 0)) + 1
    session.show2 = 1
    
    h = CAT(
        SCRIPT("""
            if ( ! $('#show_1').is(':visible')) {
                $('#show_1').animate({ height: 'show' }, 1000);
            }
            """),
            H4('SHOW 1'),
            T('COUNTER 1'),': ', session.show1,
        )
    h += LOAD('aj_load2', 'show2', args=[], ajax=True,
                times = 'infinity', timeout=UPD_TIMEOUT,
                target='show_2', # instead _id
                _style='display:none; height:0%;',
                _class='container',
            )
    
    return h # not need any view

def index():
    response.title = None
    #session.forget(response)
    session.forget(request)
    
    h = CAT()
    
    h += reload_btn(1)
    h += DIV(_id = 'reload_tag')
    
    h += LOAD('aj_load2', 'show1', args=[], ajax=True,
            times = 'infinity', timeout=UPD_TIMEOUT * 5,
            target='show_1',
            _style='display:none; height:0%;',
            _class='container',
            )
    return dict( h = DIV(h, _class='row')) # not need any view


but after reload show_1 reladind of show_2 do doubles reloads ((



понедельник, 13 апреля 2015 г., 23:00:39 UTC+3 пользователь Richard написал:
Hello,

Richard Vézina

unread,
Apr 20, 2015, 9:46:31 AM4/20/15
to web2py-users
Interresting!

Richard

def show1():
    
    session.show1 = (int(session.show1 or 0)) + 1
    session.show2 = 1
    
    h = CAT(
        SCRIPT("""
            if ( ! $('#show_1').is(':visible')) {
                $('#show_1').animate({ height: 'show' }, 1000);
            }
            """),
            H4('SHOW 1'),
            T('COUNTER 1'),': ', session.show1,
        )
    h += LOAD('aj_load2', 'show2', args=[], ajax=True,
                times = 'infinity', timeout=UPD_TIMEOUT,
                target='show_2', # instead _id
                _style='display:none; height:0%;',
                _class='container',
            )
    
    return h

def index():
    response.title = None
    #session.forget(response)
    session.forget(request)
    
    h = CAT()
    
    h += reload_btn(1)
    h += DIV(_id = 'reload_tag')
    
    h += LOAD('aj_load2', 'show1', args=[], ajax=True,
            times = 'infinity', timeout=UPD_TIMEOUT * 5,
            target='show_1',
            _style='display:none; height:0%;',
            _class='container',
            )
    return dict( h = DIV(h, _class='row'))

but after reload show_1 reladind of show_2 do doubles reloads ((


понедельник, 13 апреля 2015 г., 23:00:39 UTC+3 пользователь Richard написал:
Hello,

I create a page with multiple components inside of it (the index page is basically an empty shell for the components)... But one of there is a form in one of the embed component which as a field with a widget that trigger modal form allowing to insert a value in another table and select this inserted value (something like SELECT_OR_ADD() would do). The problem is that my form embeded in the modal which the widget append to the page with LOAD() don't load... It hang on "loading..."

Any idea?

Is it even possible to trigger a LOAD inside a LOAD?

Thanks

Richard

--

Dmitry Ermolaev

unread,
Apr 21, 2015, 9:14:35 AM4/21/15
to web...@googlegroups.com
before to reload a sub-LOAD need stop it auto-loading - for preventing from double loads of sub-LOAD component

full script:
def remake_reload_script(tag, timeout=None): # tag = '#show_2'
    return '''
        var jelement = $("%s");
        var element = jelement.get(0);
        var statement = "jQuery('%s').get(0).reload();";
        clearInterval(element.timing); // stop auto-reloading
        ''' % (tag, tag) + \
        (timeout and '''
        element.timeout = %s000;
        element.timing = setInterval(statement, %s000); // start reloading
        ''' % (timeout, timeout) or '')
        


response.js = remake_reload_script('#show_1', 3)

воскресенье, 19 апреля 2015 г., 19:54:31 UTC+3 пользователь Dmitry Ermolaev написал:

Dave S

unread,
Apr 21, 2015, 3:17:38 PM4/21/15
to web...@googlegroups.com


On Tuesday, April 21, 2015 at 6:14:35 AM UTC-7, Dmitry Ermolaev wrote:
before to reload a sub-LOAD need stop it auto-loading - for preventing from double loads of sub-LOAD component


Does this replace the reload() function that was in your post from Sunday? (Shown quoted below)

/dps

 

Dmitry Ermolaev

unread,
Apr 25, 2015, 1:36:26 AM4/25/15
to web...@googlegroups.com
yes

instead:
    response.js +=  "jQuery('#show_2').get(0).reload();"

use 
      response.js +=  remake_reload_script('#show_2', 3)

вторник, 21 апреля 2015 г., 22:17:38 UTC+3 пользователь Dave S написал:
Reply all
Reply to author
Forward
0 new messages