> On Tuesday, June 7, 2011 2:26:45 AM UTC-4, Gwayne aka Mike Veltman wrote:
> > > On Monday, June 6, 2011 9:15:27 PM UTC-4, Gwayne aka Mike Veltman wrote:
> > > > And that was it...
> > > > 
> > > > Thank you very much. Mmmm, this should go in the book..
> > > 
> > > There's also this method of pre-populating a form field:
> > > http://web2py.com/book/default/chapter/07#Pre-populating-the-form
> > 
> > Yes I know, but I did read in the mailing list that that was not a smart
> > idea.
> 
> I wasn't aware of that. Why is it not a smart idea?
> 

I am trying to find it it was actually in the mailing list a discussion about 
it and the suggestion was to use the default. 

> > Also those vars do not exist before I create the form. So you would get a
> > error if you do so.
> 
> But is there any reason you couldn't make the assignment right after the
> form is created (i.e., instead of assigning a new default right before the
> form creation, assign a value to the form var right after creation)?
> 
> Anthony

Maybe I just do it plain wrong :-)

    form = SQLFORM(db.lvstorage)
    form.vars.lunid = 2 # Does not work

Thats how I did it.

Now I have a complicated system :) My goal is/was to make the lunid 
autoincrement with each submit.

Now I use this (btw I am not a programmer so, suggestions are always welcome.)

  if not request.vars.newrecord: # For the newrecord button 
            newrecord = False
                
        if request.vars.newrecord: # For the newrecord button
                session.lunid = 2       
                newrecord = True
                                 
        if not request.args or newrecord == True:  # If called directly from 
menu or newmenu button
        
            if session.lunid == 2:
                # Default settings for the page
                db.lvstorage.lunid.default = 2
                db.lvstorage.setup_id.default = 1
                db.lvstorage.lvsize_id.default = 2
                db.lvstorage.storagemap_id.default = 1  
                session.setup_id = 1
                session.storagemap_id = 1
                session.lvsize_id = 2      
                
            else:  
                if session.lunid == 31: # Lunid 31 is managed by the 
controller so skip it
                    session.lunid = 32
                
                if request.vars.setup_id : # To make sure that if the var does 
not exist it will not change the session var
                    session.setup_id = request.vars.setup_id
                if request.vars.lvsize_id :
                    session.lvsize_id = request.vars.lvsize_id
                if request.vars.storagemap_id :
                    session.storagemap_id = request.vars.storagemap_id
                
                db.lvstorage.lunid.default = int(session.lunid)                
                db.lvstorage.setup_id.default = session.setup_id
                db.lvstorage.lvsize_id.default = session.lvsize_id
                db.lvstorage.storagemap_id.default = session.storagemap_id
            
            if request.vars.checkbox: # If checkbox is used do not increase 
lunid
                pass
            else:             
                session.lunid = int(session.lunid) + 1 # Increase lun id
            
            form = SQLFORM(db.lvstorage)

With regards,
Mike Veltman


Reply via email to