IS_NOT_EMPTY() "takes away" a dropbox with a list of items referenced by a foreign key -

43 views
Skip to first unread message

Vlad

unread,
May 19, 2019, 1:38:10 AM5/19/19
to web2py-users
In the following table - 

db.define_table('products_group_content',
    Field('products_group','reference products_group',requires=[IS_NOT_EMPTY()]),
    Field('product','reference product'),
    auth.signature)

when I add a record (using grid functionality or in the admin interface) - the products_group field doesn't have a drop box with a list of groups (it has a regular text edit field), even though this field is referencing another table. 
on the other hand, the product field does have a drop box with a list of products to pick from. 

Why the difference? Seems to me, in both cases the drop box should be in place. I have no clue why requires parameter makes any difference at all. 
What am I missing?? 

John Bannister

unread,
May 19, 2019, 7:16:40 AM5/19/19
to web2py-users
Hi Vlad,

I think I have come across this issue as well some time ago. Can you try IS_NOT_EMPY() OR IS_IN_DB(id .......)

This should hopefully bring back your drop down list.

BR
John

Anthony

unread,
May 19, 2019, 10:16:58 PM5/19/19
to web2py-users
The default validator for a reference field is IS_EMPTY_OR(IS_IN_DB(...)). When SQLFORM encounters a field without an explicit "widget" specified but with an IS_IN_SET or IS_IN_DB validator, it automatically generates a select widget with options derived from the validator.

In your case, you have replaced the default validator with your own, so you no longer get the default select widget.

Instead, try just use an IS_IN_DB() validator, which will require the selection of a value.

Anthony

Vlad

unread,
May 19, 2019, 10:19:22 PM5/19/19
to web2py-users
Got it working - 
Thank you! 

Vlad

unread,
May 19, 2019, 10:19:50 PM5/19/19
to web2py-users
got it, that makes sense - 
Thank you very much! 
Reply all
Reply to author
Forward
0 new messages