show_if issue

84 views
Skip to first unread message

Sneka R

unread,
Jul 24, 2016, 6:32:43 PM7/24/16
to web...@googlegroups.com
Can I use show_if for 2 tables?
For example:
db.table2.field.show_if = (db.table1.box==True)

To be more clear:
Model:
db.define_table(’table1’,
                         Field('title’,label=‘Workshop title :',requires=IS_NOT_EMPTY()),
                         Field(’help1’,’boolean’,label=’Need help?’))


db.define_table(’table2',
                Field(’title', 'reference table1',label='Workshop title :'),
                Field(‘help2’,’boolean’, label=’Need help?'))

Controller:
def register_workshop(): 
    workshop = db.table1(request.args(0))
    db.table2.help2.show_if = (db.table1.help1==True)

Sneka R

unread,
Jul 26, 2016, 12:07:12 PM7/26/16
to web2py-users
Is this possible at all?

Marlysson Silva

unread,
Jul 26, 2016, 1:15:55 PM7/26/16
to web2py-users
The show if statement use a query of DAL , then I think that it's perfectly possible.
But the fields that use show_if , generally are used in a SQLFORM() , and he verify if that field it's readable to SQLFORM.

Sneka R

unread,
Jul 26, 2016, 11:07:26 PM7/26/16
to web2py-users
It worked initially and do not work now.
The field help2 is visible even if the field help1==False

How do I do this?
Please I need help in figuring this out.


On Sunday, July 24, 2016 at 5:32:43 PM UTC-5, Sneka R wrote:

黄祥

unread,
Jul 27, 2016, 12:56:29 AM7/27/16
to web2py-users
pls try

def register_workshop(): 
    workshop = db.table1(request.args(0))
    # pls try choose either top or bottom
    db.table2.help2.show_if = (workshop.help1 == True)
    db.table2.help2.show_if = ((db.table1.help1 == True) & (db.table1.id == request.args(0) ) )

best regards,
stifan

Sneka R

unread,
Jul 27, 2016, 12:39:21 PM7/27/16
to web2py-users
When I used the second choice, I got the following Traceback:

Traceback

1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
Traceback (most recent call last):
File "/Users/SR/Documents/web2py/gluon/restricted.py", line 227, in restricted
exec ccode in environment
File "/Users/SR/Documents/web2py/applications/myapp/controllers/events.py", line 417, in <module>
File "/Users/SR/Documents/web2py/gluon/globals.py", line 417, in <lambda>
self._caller = lambda f: f()
File "/Users/SR/Documents/web2py/gluon/tools.py", line 4241, in f
return action(*a, **b)
File "/Users/SR/Documents/web2py/applications/myapp/controllers/events.py", line 220, in register_workshop
fields =['title','help2'])
File "/Users/SR/Documents/web2py/gluon/sqlhtml.py", line 1288, in __init__
inp = self.widgets.boolean.widget(field, default)
File "/Users/SR/Documents/web2py/gluon/sqlhtml.py", line 278, in widget
**attributes)
File "/Users/SR/Documents/web2py/gluon/sqlhtml.py", line 160, in _attributes
trigger, cond = show_if(field.show_if)
File "/Users/SR/Documents/web2py/gluon/sqlhtml.py", line 112, in show_if
base = "%s_%s" % (cond.first.tablename, cond.first.name)
AttributeError: 'Query' object has no attribute 'tablename'

On Sunday, July 24, 2016 at 5:32:43 PM UTC-5, Sneka R wrote:

Niphlod

unread,
Jul 28, 2016, 10:04:59 AM7/28/16
to web2py-users
I hate to barge in, but show_if works ONLY for very very very simple conditions: those conditions are translated at the best of possibilities to jquery selectors.... which are BY FAR not a complete uber-logic such as any DAL expression you throw at it.

!= True/False
== True/False
== value
!= value
contains(value)
belongs(list_of_values)

are the only supported, and work best when "value" is a string.

Sneka R

unread,
Jul 28, 2016, 11:35:59 AM7/28/16
to web2py-users
Thanks.
I am new to programming. 
I want to create a form based on the field selections from another table.
How can I accomplish this using web2py?
Thanks in advance.



On Sunday, July 24, 2016 at 5:32:43 PM UTC-5, Sneka R wrote:
Reply all
Reply to author
Forward
0 new messages