I missed a bit......[I did say it was a bit fiddly!]

You still need to refresh the grid when the dialog box closes. To do
this I replaced the LOAD calls with load2 which adds a url to the
component:

def load2(**args):
    """ calls LOAD and sets url attribute to enable easy refresh of
the component """
    s=Storage(**args)
    if s.url: url=s.url
    else: url=URL(c=s.c, f=s.f, args=s.args, vars=s.vars,
extension=s.extension)
    return LOAD(_url=url, **args)
###################################################################################
Then in the view:

// refresh a web2py component using url attribute
function refresh(component) {
        web2py_ajax_page("get", $('#'+component).attr("url"), null ,
component)
}
#################################################
and in the controller you add "refresh('gridid')" to v._onacceptjs.

If you need to you can refresh other components in the same way e.g.
if your edit form has a count of the rows on the grid then you might
want to refresh it.

Thats it!!!

On Dec 21, 8:03 pm, apple <simo...@gmail.com> wrote:
> I have done something similar to what you are looking for but it was a
> little fiddly in places (if someone can suggest a better way I would
> be delighted!). My application had some extra functionality but the
> gist of it is:
>
> You have a form and a grid. You can put these on the same page easily
> using LOAD component.
>
> {{=LOAD(f='edit.load', ajax=True, args=.....}}
> {{=LOAD(f='grid.load', ajax=True, args=.....}}
>
> Now you have them on the same page.
>
> ###########################################
> But when you add/edit a grid row then you have 2 forms and 2 submit
> buttons on the page which is odd. So I used a dialog box for the add/
> edit functions. This is actually quite easy as the majority of the
> code is already included in web2py.
>
> In the view you do this:
>
> // create dialogbox
> document.write("<div id='dialogdiv' style='display:none'></div>")
> $(document).ready(function(){
>         $('#dialogdiv').dialog({autoOpen : false, modal : false, width :
> 'auto'});})
>
> // open url in dialog box
> function dialog(url) {
>         web2py_ajax_page("get", url, {_newformjs:"$
> ('#dialogdiv').dialog('open')"} , 'dialogdiv')
>
> }
>
> Now if you pass any url to the javascript dialog function it will call
> the controller and open the form in a dialog box; and return any form
> errors inside the dialog box. And only half a dozen lines of code!!
>
> #######################################
> Now you need to make the form open and close.
>
> In the edit controller (for person) you do this:
>
> if form.process(.....).accepted:
>         response.js=v._onacceptjs
>         return
> elif form.errors:
>     pass
> else:
>     response.js=v._newformjs
> ############################################################
> and in the grid controller you setup the dialog close and rewire the
> buttons
>
> def dialog(url):
>     """ returns javascript to show the view as a dialog box """
>     return "dialog("+quote(url)+"); return false;"
>
> def grid():
>     editvars['_onacceptjs']="$('#dialogdiv').dialog('close');"
>
>     links.append(lambda row: A(SPAN(_class='ui-icon ui-icon-pencil'),
>                        SPAN('Edit',_class='ui-button-
> text',_title='Edit'),
>                        _onclick=dialog(URL(editcontroller,
> vars=editvars, args=[a.tablename, row.id])),
>                        _class='ui-button-text-icon-primary',
> _id='edit'))
>
> On Dec 21, 1:54 pm, Cliff <cjk...@gmail.com> wrote:
>
>
>
>
>
>
>
> > Remember web2py uses the term 'form' in a very specific way.
>
> > So don't think about a web2py form for CRUD operations on child
> > records.  You need a way to dynamically update the web page so it can
> > manage the child records.  Web2py provides several approaches to this
> > problem.
>
> > The image blog example in the book outlines a design approach that
> > will solve your 
> > problem.http://web2py.com/books/default/chapter/29/3#An-image-blog
>
> > Also look here for other 
> > solutions:http://web2py.com/books/default/chapter/29/11#The-ajax-functionhttp:/...
>
> > On Dec 21, 1:22 am, Martin Weissenboeck <mweis...@gmail.com> wrote:
>
> > > Ok, thank you - I will try it.
>
> > > 2011/12/21 Nik Go <nikolai...@gmail.com>
>
> > > > Martin,
>
> > > > I have a feeling that what you're looking is "multi-form updates" (try 
> > > > to
> > > > search for that term) where a parent record (your "person") and child
> > > > record (your "cvrows") are updated simultaneously.
>
> > > > On Wednesday, December 21, 2011, Jim Steil wrote:
>
> > > >>  have you looked at SQLFORM.smartgrid?
>
> > > >>     -Jim
>
> > > >> On 12/20/2011 1:39 PM, Martin Weissenboeck wrote:
>
> > > >> Thanks for all hints, I have found some new ideas and I will try a ot 
> > > >> of
> > > >> new things.
>
> > > >> But -may I describe my problem in detail?
> > > >> There should be a website for persons  who want to apply for a job.
>
> > > >> My present solution:
> > > >> Table "person" contains name, date of birth, phone number and so on.
> > > >> Table "cv" (curriculum vitae) contains for each person zero or more 
> > > >> rows.
> > > >> Each row consists of the dates of the start and the end of the 
> > > >> occupation
> > > >> and some details about the occupation.
>
> > > >> Page one is a SQLFORM of table "person" with a submit button. If the 
> > > >> form
> > > >> is filled without errors the user is redirected to the second page. 
> > > >> There
> > > >> is a SQLFORM.grid of table "cv" on this page. Of course person.id from
> > > >> page one is used on page two. Page two has it's own submit button.
>
> > > >> My question:
> > > >> It would be nice to have both forms (the form for the person and the 
> > > >> form
> > > >> for some rows of cv) on one page with only one submit button. Is there 
> > > >> any
> > > >> way to concatanate these two forms?
>
> > > >>  2011/12/19 Cliff <cjk...@gmail.com>
>
> > > >>> Martin,
> > > >>> There has been discussion about manipulating grid.  Search for threads
> > > >>> containing form.create()
>
> > > >>> Also perhaps Anthony will chime in.  He knows this stuff pretty well.
>
> > > >>> apple,
> > > >>> > Surely the grid is just a grid and does not have a submit button?
>
> > > >>>  SQLFORM.grid is much more than that.
>
> > > >>>http://web2py.com/books/default/chapter/29/7#SQLFORM.grid-and-SQLFORM...)
>
> > > >>> On Dec 19, 9:48 am, apple <simo...@gmail.com> wrote:
> > > >>> > Surely the grid is just a grid and does not have a submit button?
>
> > > >>> > Do you mean that you have a grid linked to a form and you want to
> > > >>> > refresh it when the form is submitted?
>
> > > >>> > On Dec 18, 9:10 pm, Martin Weissenboeck <mweis...@gmail.com> wrote:
>
> > > >>> > > Hi,
> > > >>> > > I have one form created with SQLFORM and another form created with
> > > >>> > > SQLFORM.grid. Each form has its own submit-button.
> > > >>> > > Is there a simple way to concatanate these forms to one form, 
> > > >>> > > which
> > > >>> could
> > > >>> > > be sent with one submit-button?
>
> > > >>> > > Regards, Martin

Reply via email to