Valuelists depending on logged in user
4 posts
• Page 1 of 1
Hi,
Hope someone can point me in the right direction - this problem is driving me nuts I'm trying to filter the valuelist entries for a field based on records owned by the logged in user. For example: I have a "cash_accounts" table which has all the user's bank accounts: mysql> describe cash_accounts; +---------------+--------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +---------------+--------------+------+-----+---------+----------------+ | id | int(11) | | PRI | NULL | auto_increment | | user_id | int(11) | | | 0 | | | country_id | int(11) | | | 0 | | | currency_id | int(11) | | | 0 | | | description | varchar(100) | | | NULL | | | interest_rate | float | | | 0 | | +---------------+--------------+------+-----+---------+----------------+ ..and for example the property_costs table - when I add a new record, I don't want to have all the bank account details from cash_accounts listed, only the one for this user. mysql> describe property_costs; +-----------------+--------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-----------------+--------------+------+-----+---------+----------------+ | id | int(11) | | PRI | NULL | auto_increment | | user_id | int(11) | | | 0 | | | property_id | int(11) | | | 0 | | | cash_account_id | int(11) | | | 0 | | | description | varchar(100) | | | NULL | | | value | bigint(20) | | | 0 | | +-----------------+--------------+------+-----+---------+----------------+ My fields.ini in tables/property_costs has: [__filters__] user_id="$user->val('id')" My valuelists.ini has: [cash_account_id] __sql__ = "select id,description from cash_accounts order by id asc" ..which is obviously selecting all the records - can I use a delegate class to filter these results ? Any help would be greatly appreciated ! Thanks, Allan. PS - thanks for an awesome product
Hi Allan, You can define valuelists in the delegate class if you need them to be dynamic.Ê This post has a little bit of info on it: http://framework.weblite.ca/forum/dataface-users/909107879 A couple things to be careful of if you do this:Ê Because of the way that Dataface loads its data you have to make sure that ALL values are available when you are displaying the data (e.g. list view).Ê Otherwise the fields that use the valuelist will show up blank.Ê You should do a check to see if the current action is an 'edit' action, and then - only then - use the filtered valuelist.Ê Otherwise output all of the values. Because of this caveat, I generally use javascript to filter the values on the edit form - but don't really have any examples I can throw up right now of the Javascript way.. if you are interested in it, I'll see what I can dig up. Best regards Steve
Another place where dynamic valuelists have been discussed: http://framework.weblite.ca/forum/dataface-users/378327080 This post makes a good point about caching the result of the valuelist method so that it doesn't get called every time. -Steve
4 posts
• Page 1 of 1
Who is onlineUsers browsing this forum: No registered users and 29 guests |