Fixed...
Or maybe, let's say... ADDED.
Because this feature has never been working before. That's why I understood very well your request.
This is a very good one. Thanks for the idea.
www.j-cook.pro/index.php/docs/versions/223-2-8-6
Actually it is limited and will not work with Ajax groups for the moment.
If you choose Ajax, without a parent group, it will work.
In the version 3.0 of Cook it will work with Ajax, because the Ajax fields are 100% rewritten (not published yet), and it works in that version to come, but for the moment, just use a normal non-ajax combo.
The reason is because for current ajax combo, the groups values are furnished by the model and with joins over the item. This is heavy stuff, so it would be a heavy nightmare to make this defaulting feature in that terms. Also because I know I would write heavy code that I will deprecate very soon.
A new static function is born in :
classes/model/item.php[code]
(in this example, my component is Demo12500)
[code]/**
* Returns the default item of a table.
*
* @access public static
* @param string $table The table name.
* @param string $defaultField The field containing the default flag.
* @param string $fieldValue The field value to return. If null, return the full object.
*
*
* @since 2.8.6
*
* @return mixed () Can be stdClass in case of a full object, or mixed value depending of the requested value field.
*/
public static function getDefaultItem($table, $defaultField = 'default', $fieldValue = 'id')
{
// Get default country
$model = CkJModel::getInstance(ucfirst($table), 'Demo12500Model');
$model->addWhere('a.' . $defaultField . ' = 1');
$defaultItems = $model->getItems();
// Not found
if (!count($defaultItems))
return null;
// Take first
$defaultItem = $defaultItems[0];
if (empty($fieldValue))
return $defaultItem;
return $defaultItem->$fieldValue;
}
and this is called in your item model in the function
loadFormData()
Hope you will like it.