Page 1 of 1

widget type lookup with custom SELECT

PostPosted: Thu Sep 20, 2012 6:16 am
by xyloweb
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()

Re: widget type lookup with custom SELECT

PostPosted: Mon Sep 24, 2012 9:54 am
by shannah
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

Re: widget type lookup with custom SELECT

PostPosted: Mon Sep 24, 2012 12:28 pm
by xyloweb
Thanks steve for your reply.
I think a SQL view is an interesting response.

And many thanks for your great product !