IS_IN_SET with or without combo box !!

Look at this piece of code :

CURRENCY_SET = [
                   T('EGP'),
                   T('EUR'),
                   T('USD')

                ]
db.define_table('service',
                Field('name', 'string', label=T('Name')),
                Field('description', 'string', label=T('Description')),
                Field('price', 'double', label=T('Price')),
                Field('currency', 'string', required=True,
                      requires=[
                                IS_IN_SET(CURRENCY_SET, zero=T('--choose currency--'))
                                ]

                                ),

                Field('image', 'upload', label=T('Photo'))

                )

You expect it to get you a combo box in your field to choose among different currencies in your system
but it doesn’t offer you that , it just give you a Normal text field that you should enter in it the currency
and will not accept values except ‘EGP’, ‘EUR’, or ‘USD’

So what’s wrong and how can I get the combo box that I want ?

Simply, when you want IS_IN_SET to get you a combo box , don’t use it like this :

requires=[IS_IN_SET(CURRENCY_SET, zero=T('--choose currency--'))]

instead use :

requires=IS_IN_SET(CURRENCY_SET, zero=T('--choose currency--'))

Tricky hah ?  😀

Any way there’s a solution for this, please refer to This post

Advertisements

8 Responses to IS_IN_SET with or without combo box !!

  1. web2py says:

    I think it’s on purpose, this behavior is the same as IS_IN_DB() and strangely it’s mentioned on the web2py’s manual.It’s just hard to take your attention from the 1st time

  2. web2py says:

    Hi Richard,

    I discussed this issue in more details in this post:
    https://web2py.wordpress.com/2010/04/29/validators-between-classical-and-professional-usage/

    and I discussed the solution too.

  3. Hemebond says:

    Not a combobox. It is just a drop-down menu (SELECT element).

  4. 1. How can i retrieve from the database all the services with the EUR currency?

    2. My second question is, if i have 2 types of clients: company and individuals, when the user creates a client, it has to first choose from the 2 types of clients and accordingly, a form should appear based on the type of client. I should have the 2 types of clients as 2 separate tables and a SET with each type? What do you think is the best approach? Based on question 1, i should been able to retrieve all the companies i have as clients or individuals.

    Thank you!

    • web2py says:

      Hello, I don’t use web2py since a while now.
      I can’t really answer your questions, sorry for that.
      may be some day I get back to that blog and start re-using web2py again.

      • The obvious question: why don’t you use it anymore and what are you using now? Thanks.

      • web2py says:

        The time we used web2py, my technical manager was experimenting various kinds of Frameworks
        He likes web2py design.I liked it too.
        The only problem with it as this time, is you have to write your own solution for every problem you have
        it was not very modular.

        After that we moved to Django … Django is very powerful and mature and you can find almost any Django app for any problem we have.
        You can find even social apps.
        Development in companies means time and time means money, so if there’s a mature application right there that is tested and can get your work done
        you probably wants to use it because it will reduce the effect of re-writing functionality your self and testing it.
        Django was mature than web2py at that time.
        I really have no idea about web2py now because I was very busy to look at it.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: