Welcome, Guest
Username: Password: Remember me

TOPIC: [ADDED] Auto populate the defaut item in Foreign Key Combo Form

Default Table field Bug 13 Jun 2016 11:01 #14040

  • organicwebs
  • organicwebs's Avatar
  • Offline
  • Premium Member
  • Chris
  • Posts: 133
  • Thank you received: 21
  • Karma: 4
I have a Membership table that lists Company names and Membership type.

I have created a table for the Membership types - and included the default field (via the wizard) .

In the Membership Type table I have entered two records - "Individual" and "Corporate". I have set the "Individual" record as the default record.

But when I add a new record into my Membership Table - the member type "Individual" is not selected as a default.

I can do all this by forking - but why does this not work with the JCook builder?

(PS: if this forum allowed png files as attachments - I could have shown screen dumps).
Just call me Chris :)
Last Edit: 13 Jun 2016 11:02 by organicwebs.
The administrator has disabled public write access.

Default Table field Bug 13 Jun 2016 12:23 #14044

  • Romkabouter
  • Romkabouter's Avatar
  • Offline
  • Elite Member
  • Posts: 310
  • Thank you received: 131
  • Karma: 48
How did you set the individual as the default records?
I do not think there is such thing, because what will happen if someone were to delete that record?

There can be a default setting on a enumeration field, is that what you mean?
The administrator has disabled public write access.

Default Table field Bug 13 Jun 2016 12:43 #14045

  • organicwebs
  • organicwebs's Avatar
  • Offline
  • Premium Member
  • Chris
  • Posts: 133
  • Thank you received: 21
  • Karma: 4
Hi Romkabouter - I'm not talking about the enumeration field.

When creating a Table in JCook, under the Wizard, you can add a Default field for the Table. (Just like you would the Author / Checked out / Creation Date field). Its like a toggled Boolean, where only one record in the table can be set true. When entering records for this table (via the forms) - you can then select a particular record to be the default.

If this is not to define a default record for a list/selection box - what is its purpose?

I have seen this in other Joomla components where it works - say in a photo gallery where you can set the Default Photo Category for new photo albums - or to select the default picture to be used as the album thumbnail.

To answer your question, if a user deleted the default record, then the list/selection box would select another record (maybe the first record - or none at all). But I'm not concerned with this.
Just call me Chris :)
The administrator has disabled public write access.

Default Table field Bug 13 Jun 2016 16:12 #14058

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 987
  • Karma: 140
I undrstand what you mean.

I will check and fix it in this days. Maybe tonight.
Coding is now a piece of cake
The administrator has disabled public write access.

Default Table field Bug 14 Jun 2016 14:17 #14061

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 987
  • Karma: 140
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.
Coding is now a piece of cake
The administrator has disabled public write access.
The following user(s) said Thank You: MorganL, organicwebs
Time to create page: 0.076 seconds

Get Started