insert a default value into a text of a table form

18 views
Skip to first unread message

MadWalker

unread,
Dec 1, 2008, 10:39:49 PM12/1/08
to web2py Web Framework
i need to know that if i can insert a default value if i do not want
to type the text in
'
comments=SQLFORM(cynotedb.comment,fields=['author','entry_id','body')
this is the code for the form i using
can i do something like
comments=SQLFORM(cynotedb.comment,fields=['author','entry_id'])
and the 'body' will have a default value like "hello" insert in it

the end result will show "ABC say hello"
the view code showing of the comment is by
"{{=comment.author}} say {{=comment.body}}"

is it possible
if so,
how can i do it?

pls pardon my english
Good day

Fran

unread,
Dec 2, 2008, 2:59:12 AM12/2/08
to web2py Web Framework
I too would like to pre-populate Form fields (ideally with T2).
For me, the default entry should be the current value (if it exists),
the default value (if defined) or blank.

Looking forward to a solution :)

Yarko Tymciurak

unread,
Dec 2, 2008, 3:48:47 AM12/2/08
to web...@googlegroups.com
somewhere before your SQLFORM(),
a statement such as:

cynotedb.comment.body.default='hello'

will pre-populate.

This should work the same way before calling a t2 form creating function.

Fran

unread,
Dec 2, 2008, 4:39:25 AM12/2/08
to web2py Web Framework
T2 works anyway by default - *lovely*.

voltron

unread,
Dec 2, 2008, 4:45:17 AM12/2/08
to web2py Web Framework
This is the way I do things like that

you can use Javascript or do it directly in the controller.

#Javascript

$("#my_textarea").text("Put some text here....");


#In the controller:

before form.accepts(), assign values, an example:

form.components[0].components[1].components[1].components[0].attributes
['requires'][0].error_message = T("Please fill in your email address")

I hope that helped

mdipierro

unread,
Dec 2, 2008, 9:54:19 AM12/2/08
to web2py Web Framework
cynotedb.comment.body.default='hello'

serves two purposes
1) prepopultes forms
2) sets a default for the field when doing cynotedb.comment.insert
(...) and the bdy field is missing

Yarko Tymciurak

unread,
Dec 2, 2008, 2:49:45 PM12/2/08
to web...@googlegroups.com
and there should be nothing wrong with the default changing w/ context - that is, save whatever the current default is, change it for your context;  restore previous default when done.

There might be something to check into if you want to set a contextual default when the previous default was not set....  does anyone know if there is any issue here?

MadWalker

unread,
Dec 3, 2008, 5:32:16 AM12/3/08
to web2py Web Framework
Thank for the code
when set to default
will it set to all to default too?

thanks and good day

On Dec 2, 4:48 pm, "Yarko Tymciurak" <yark...@gmail.com> wrote:
> somewhere before your SQLFORM(),a statement such as:
>
> cynotedb.comment.body.default='hello'
>
> will pre-populate.
>
> This should work the same way before calling a t2 form creating function.
>
Reply all
Reply to author
Forward
0 new messages