widget type lookup with custom SELECT
Archived from the Xataface Users forum.
xyloweb — Thu Sep 20, 2012 6:16 am
Hi,
I use widget:type lookup and I want to know if it’s possible to customize table select
Example : user table with contract end field > now()
shannah — Mon Sep 24, 2012 9:54 am
One solution would be to use the widget:filters:* directive and create a grafted field on the users table that is simply a boolean (0 or 1) value.
E.g.
In the users fields.ini file
- Code: Select all
__sql__ = "select u.*, if(contract_end>now(),1,0) as contract_active from users u"
Then in your lookup widget field def
- Code: Select all
[myfield] widget:type=lookup widget:table=users widget:filters:contract_active=1
Alternatively you could just create a view on the users table that includes only the users that you want in the lookup. Then reference that view from the lookup widget def instead of your actual users table.
-Steve
xyloweb — Mon Sep 24, 2012 12:28 pm
Thanks steve for your reply.
I think a SQL view is an interesting response.
And many thanks for your great product !