Some beginner questions on form

9 views
Skip to first unread message

pierreth

unread,
Oct 27, 2010, 8:45:59 PM10/27/10
to web2py-users
Hello,

I am doing my first application with web2py and I don't know how to do
some things with forms.

Like I would like to show a drop menu to show the possible values for
a text field. How can I specify this menu with define_table?

Another thing that I would like to do is format postal code and phone
numbers with javascript when the user leaves a field.

Could you guide me on this?

mdipierro

unread,
Oct 27, 2010, 11:10:32 PM10/27/10
to web2py-users


On Oct 27, 7:45 pm, pierreth <pierre.thibau...@gmail.com> wrote:
> Hello,
>
> I am doing my first application with web2py and I don't know how to do
> some things with forms.
>
> Like I would like to show a drop menu to show the possible values for
> a text field. How can I specify this menu with define_table?
>

Field('name',requires=IS_IN_SET(('value1,'value2',value3')))

> Another thing that I would like to do is format postal code and phone
> numbers with javascript when the user leaves a field.

<script>
jQuery(document).ready(function(){
var t=jQuery('#table_field');
t.keyup(function(){t.val(format(t.val());});
});
</script>

where "table" and "field" are your table and field names. format(...)
is the function that formats the input into output and you need to
define it in JS.

pierreth

unread,
Oct 28, 2010, 8:30:53 PM10/28/10
to web2py-users
On 27 oct, 23:10, mdipierro <mdipie...@cs.depaul.edu> wrote:
>
> Field('name',requires=IS_IN_SET(('value1,'value2',value3')))

This is cool. Can I have valuex in the db while presenting something
else to the user (I want to value in my db to be always in English but
I need to translate these values for the user) without having to do a
conversion function that will translate values send my the form to
English?

David Marko

unread,
Oct 29, 2010, 3:22:42 AM10/29/10
to web2py-users
Yes, you can use dictionary to define values e.g.
Field(

'name',requires=IS_IN_SET({'key1':'label1','key2':'label2','key3':'label3'})
)

David
Message has been deleted

pierreth

unread,
Oct 29, 2010, 12:06:55 PM10/29/10
to web2py-users
On 29 oct, 03:22, David Marko <dma...@tiscali.cz> wrote:
> Yes, you can use dictionary to define values e.g.
> Field(
>
> 'name',requires=IS_IN_SET({'key1':'label1','key2':'label2','key3':'label3'})
> )
>
> David
>
I'm beginning to really like web2py I think!

villas

unread,
Oct 29, 2010, 12:32:05 PM10/29/10
to web2py-users
>>requires=IS_IN_SET({'key1':'label1','key2':'label2','key3':'label3'})

@David - thanks for reminding us of this.

Book editors please note...
The fact that IS_IN_SET can accept a dict should be in the Book?
(Please forgive me if I missed it there!).

-D

mdipierro

unread,
Oct 29, 2010, 2:57:17 PM10/29/10
to web2py-users
It can also take a list of tuples. It will work like a dict of
(key,value) but preserves sorting.

villas

unread,
Oct 29, 2010, 7:48:46 PM10/29/10
to web2py-users
Tuples. Even better, I didn't realise that advantage regarding
sorting.
Also in the book, please? :)

pierreth

unread,
Oct 29, 2010, 8:35:47 PM10/29/10
to web2py-users
On 29 oct, 19:48, villas <villa...@gmail.com> wrote:
> Tuples.  Even better,  I didn't realise that advantage regarding
> sorting.
> Also in the book, please?  :)

Now yet in the book. A wonder that should be there!

pierreth

unread,
Oct 29, 2010, 8:35:54 PM10/29/10
to web2py-users
On 29 oct, 19:48, villas <villa...@gmail.com> wrote:
> Tuples.  Even better,  I didn't realise that advantage regarding
> sorting.
> Also in the book, please?  :)

pierreth

unread,
Nov 2, 2010, 5:44:51 PM11/2/10
to web2py-users
I have a blank line in the menu when I use IS_IN_SET. How can I remove
it?

mdipierro

unread,
Nov 2, 2010, 5:54:18 PM11/2/10
to web2py-users
IS_IN_SET(...,zero=None)

pierreth

unread,
Nov 2, 2010, 6:42:05 PM11/2/10
to web2py-users
I have:

IS_IN_SET("Dr", "Dre", "M.", "Me", "Mme", "Mlle", "Mr", "Miss", "Mrs",
"hon", zero=None)

and it changes nothing. Do you mean something else?

Bruno Rocha

unread,
Nov 2, 2010, 6:53:25 PM11/2/10
to web...@googlegroups.com
You can try

IS_IN_SET(["Dr", "Dre", "M.", "Me", "Mme", "Mlle", "Mr", "Miss", "Mrs",
"hon"], zero=None)

2010/11/2 pierreth <pierre.t...@gmail.com>

pierreth

unread,
Nov 2, 2010, 7:09:33 PM11/2/10
to web2py-users
OK, it works when the enumeration is in a list but not when the same
enumeration is in a tuple.

Thanks.

On 2 nov, 18:53, Bruno Rocha <rochacbr...@gmail.com> wrote:
> You can try
>
> IS_IN_SET(["Dr", "Dre", "M.", "Me", "Mme", "Mlle", "Mr", "Miss", "Mrs",
> "hon"], zero=None)
>
> 2010/11/2 pierreth <pierre.thibau...@gmail.com>

Jonathan Lundell

unread,
Nov 2, 2010, 7:38:16 PM11/2/10
to web...@googlegroups.com
On Nov 2, 2010, at 4:09 PM, pierreth wrote:
>
> OK, it works when the enumeration is in a list but not when the same
> enumeration is in a tuple.

A tuple works fine, but zero=None isn't part of the tuple.

IS_IN_SET(("Dr", "Dre", "M.", "Me", "Mme", "Mlle", "Mr", "Miss", "Mrs", "hon"), zero=None)

pierreth

unread,
Nov 3, 2010, 1:57:23 PM11/3/10
to web2py-users
On Nov 2, 7:38 pm, Jonathan Lundell <jlund...@pobox.com> wrote:
> On Nov 2, 2010, at 4:09 PM, pierreth wrote:
>
> A tuple works fine, but zero=None isn't part of the tuple.
>
> IS_IN_SET(("Dr", "Dre", "M.", "Me", "Mme", "Mlle", "Mr", "Miss", "Mrs", "hon"), zero=None)
>

You are right. I was wrong.
Reply all
Reply to author
Forward
0 new messages