Default value based on pre-filter?

FilMar

Member
I wonder if this is possible?

I have a list but use it in 2 places in Joomla where I set a different pre-filter on a field.

Can I set the default value of that field to the pre-filter value when I add a new record?



Greetings,

Filip
 
When you say you use it in 2 different places, I assume there are 2 menu items.

In that case, in the element configuration Options - Default, write some php code that gets the menu item and then uses that to determine the value that should be returned as the default value when a new row gets added.

For example, lets assume the field being filtered is named 'color' and...
You have one menu item (menu id#123) where the list is pre-filtered to color = 'red'
You have another menu item (menu id #156) where the list is pre-filtered to color = 'green'

The 'Default' php would be...
PHP:
$app = JFactory::getApplication();
$menu = $app->getMenu();
$active = $menu->getActive();
$itemId = $active->id;
/* if you need other params from the menu */
// $menuparams = $menu->getParams($itemId);

switch ($itemId) {
    case '123':
        $retval = 'red';
    case '156':
        $retval = 'green';
    default:
        $retval = '';
}
return $retval;

(Don't forget to set 'Eval' to 'Yes'.)

See Element default examples.
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top