I would recommend

    db.data.field.default='value'
    form = crud.create(db.data, onaccept=give_update_permission)
Massimo

On Apr 16, 11:20 am, Mathieu Clabaut <mathieu.clab...@gmail.com>
wrote:
> I have used form.element to prepopulate a form :
>
>     form = crud.create(db.data, onaccept=give_update_permission)
>
>     # add current date as default form
>
>     form.element('input', _name="date")['_value'] =
>
> > time.strftime("%Y-%m-%d")
>
> At this point, form is still not a string but an HTML Helper which provides
> DOM access.... (Correct me if I'm wrong).
> Are there some cons for this method (I prefer it as it does not alter the
> model defaults).
>
> -Mathieu
>
> On Fri, Apr 16, 2010 at 17:34, Thadeus Burgess <thade...@thadeusb.com>wrote:
>
> > Because SQLFORM builds the HTML as soon as you instantiate the class.
> > So you cannot edit anything after you create your form, since all of
> > the html is already built, in strings.
>
> > Specifying the default is the way to go here (annoying... I know).
>
> > I usually perform the following
>
> > if record_id:
> >   record = db.user[record_id]
> >   db.user.id.default = record.id
> >   db.user.name.default = record.name
> >   ... etc etc
>
> > form = SQLFORM.factory(
> >  db.user.name, db.user.email, Field('CustomField', default='hi')
> > )
>
> > --
> > Thadeus
>
> > On Fri, Apr 16, 2010 at 9:57 AM, salbefe <salb...@gmail.com> wrote:
> > > Thank you Massimo,
>
> > > But
>
> > >        db.user.id.default = user.user.id
> > >        db.user.name.default = user.user.name
> > >        db.user.email.default = user.user.email
> > >        db.addr.city.default = user.addr.city
>
> > > is the rigth way to preopulate a SQLFORM.factory form?????
>
> > > Why not once the form is defined, can I do form.vars.title =
> > > 'something' for example????
>
> > > Thanks
>
> > > On 16 abr, 15:35, mdipierro <mdipie...@cs.depaul.edu> wrote:
> > >> There is not such function.
>
> > >> I think by
>
> > >>            if change_user_data(user):
>
> > >> he actually means
>
> > >>            if user is allowed change do what he is trying to do:
>
> > >> depending on the logicl you may not need this if statement at all.
>
> > >> Massimo
>
> > >> On Apr 16, 6:55 am, salbefe <salb...@gmail.com> wrote:
>
> > >> > Hello,
>
> > >> > I have a SQLFORM.factory form that I need to prepopulate with some
> > >> > data from a database.
>
> > >> > id_nodo = request.args(0)
>
> > >> > ## I get the data from the database
> > >> > nodo = db(db.node.id==id_nodo).select().first()
> > >> > detalle = db(db.node_details.node_id==id_nodo).select().first()
>
> > >> >  ##Now I need to prepolutate the fields title and body that I get from
> > >> > the database
> > >> >  ## title = nodo.title, body = detalle.body
> > >> >  form = SQLFORM.factory(db.node.title,db.node_details.body)
> > >> >     if form.accepts(request.vars,session):
>
> > >> >         response.flash='Form accepted'
>
> > >> >     return dict(form=form)
>
> > >> > As I read on this threadhttp://
> > groups.google.es/group/web2py/browse_thread/thread/e2301b5cc3a...
> > >> > somebody with the same problem as me did the following:
>
> > >> > user = db((db.user.id == req_user_id) & (db.addr.user ==
> > >> > req_user_id)).select()[0]
>
> > >> >         db.user.id.default = user.user.id
> > >> >         db.user.name.default = user.user.name
> > >> >         db.user.email.default = user.user.email
> > >> >         db.addr.city.default = user.addr.city
>
> > >> >         form =
> > >> > SQLFORM.factory(db.user.name,db.user.rname,db.addr.city)
>
> > >> >         if form.accepts(request.vars, session):
>
> > >> >            # change the user data
> > >> >            if change_user_data(user):
> > >> >               user.user.update_record(name=form.vars.name) # <----
> > >> >               user.addr.update_record(city=form.vars.city) # <----
> > >> >               response.flash = 'form accepted'
> > >> >            else:
> > >> >               response.flash = 'form not accepted'
> > >> >           redirect(URL(r=request,f='index'))
>
> > >> > I do not understand  "if change_user_data(user):"
>
> > >> > I have tried :
>
> > >> >    db.node.title.default = nodo.title
> > >> >    db.node_details.body = detalle.body
> > >> >    form = SQLFORM.factory(db.node.title,db.node_details.body)
> > >> >     if form.accepts(request.vars,session):
> > >> >        if change_node_data(node):
> > >> >        .......................................
> > >> >        ......................................
>
> > >> > but I get an execption ('global name change_node_data is not defined'.
> > >> > Could anyone tell me how can I prepolutate the SQLFORM.factory form???
>
> > >> > Why is the function change_user_data used in that example if is not
> > >> > defined ????
>
> > >> > Thanks in advance
>
> > >> > --
> > >> > Subscription settings:
> >http://groups.google.com/group/web2py/subscribe?hl=en

Reply via email to