Welcome, Guest
Username: Password: Remember me

TOPIC: Two information in a combobox

Two information in a combobox 29 Apr 2012 10:28 #2181

  • VeCrea
  • VeCrea's Avatar
  • Offline
  • Platinum Member
  • Absolute JCook fan
  • Posts: 473
  • Thank you received: 100
  • Karma: 30
Hi,
I would like a combobox to contain more than 1 information.
Right now, combobox uses the label of the fk. In this case, it's the "USERNAME" field of the user table.
I would like to have both the USERNAME and the NAME of the user.
Some infos i found out about :
In the _form.php:
<?php echo JDom::_('html.form.input.select', array(
												'dataKey' => 'garage',
												'dataObject' => $this->vhu,
												'list' => $this->lists['fk']['garage'],
												'listKey' => 'id',
												'labelKey' => 'username',
												'nullLabel' => "RECYCAR_JSEARCH_SELECT_GARAGE",
												'required' => true
												));
				?>
Ok, there's the username. I tried a call to the 'name' here. Wouldn't work, and it's normal because the select combo is constructed via select.php
function __construct($args)
	{

		parent::__construct($args);

		$this->arg('list'		, 6, $args);
		$this->arg('listKey'	, 7, $args, 'id');
		$this->arg('labelKey'	, 8, $args);
		$this->arg('size'		, 9, $args);
		$this->arg('nullLabel'	, 10, $args);
		$this->arg('groupBy'	, 11, $args);
		$this->arg('domClass'	, 12, $args);
		$this->arg('selectors'	, 13, $args);


		//Reformate items
		$i = 0;
		$newArray = array();
		if (count($this->list))
		foreach($this->list as $item)
		{
			if (is_array($item))
			{
				$newItem = new stdClass();
				foreach($item as $key => $value)
				{
					$newItem->$key = $value;
				}

				$newArray[$i] = $newItem;

			}
			$i++;
		}

		if (count($newArray))
			$this->list = $newArray;


	}
And i thought i found what i needed in combo.php with
function buildOption($item, $listKey, $labelKey, $prefix = '')
	{
		if (!isset($item->$listKey))
			$item->$listKey = null;

		$selected = ($item->$listKey == $this->dataValue);

		$html =	'<option value="'
			.	htmlspecialchars($item->$listKey, ENT_COMPAT, 'UTF-8')
			. 	'"'
			.	($selected?' selected="selected"':'')
			.	'>'
			.	$prefix . $item->$labelKey
			. 	'</option>'.LN;

		return $html;
	}
But there again, trying to display two infos didn't succeed...
What am i missing ?
Thanks for reading all this ;-)
Last Edit: 01 May 2012 20:16 by admin.
The administrator has disabled public write access.

Re: Two information in a combobox 30 Apr 2012 15:38 #2189

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 984
  • Karma: 140
Don't be worry about that,

I just finished (for you) this really easy feature.

In the next upgrade, you'll be able to create patterns in the JDom 'labelKey' property :

For instance (your example) :
<?php echo JDom::_('html.form.input.select', array(
				'dataKey' => 'garage',
				'dataObject' => $this->vhu,
				'list' => $this->lists['fk']['garage'],
				'listKey' => 'id',
//HERE
				'labelKey' => '<%username%> <%name%>',  // Instead of 'username'


				'nullLabel' => "RECYCAR_JSEARCH_SELECT_GARAGE",
				'required' => true
						));
				?>

Will be possible on select.combos and html.fly.xxx JDom instances.
EDIT : Also possible on a group label in select.combo

I will advice you when ready.

Best regards.

PS : The jobs are going well... ;-)
Coding is now a piece of cake
Last Edit: 30 Apr 2012 15:40 by admin.
The administrator has disabled public write access.
The following user(s) said Thank You: VeCrea, edwardcox

Re: Two information in a combobox 01 May 2012 07:13 #2192

  • VeCrea
  • VeCrea's Avatar
  • Offline
  • Platinum Member
  • Absolute JCook fan
  • Posts: 473
  • Thank you received: 100
  • Karma: 30
I'm getting short on beautiful quotes to tell you how much you're the one ;-)
Last Edit: 01 May 2012 07:28 by VeCrea.
The administrator has disabled public write access.
The following user(s) said Thank You: admin

Re: Two information in a combobox 01 May 2012 20:01 #2195

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 984
  • Karma: 140
Done.

Now at any moment you can define patterns of datas.

for example : "<%name%> <%surname%> (<%email%>)"
will output : Jean Dupond (This email address is being protected from spambots. You need JavaScript enabled to view it.)

In JDom:
In any child class of 'html.fly' (dataKey property)
In html.form.input.select (labelKey property, AND in goupBy entries)

That is why JDom powerful : Inheritence !!!
Coding is now a piece of cake
The administrator has disabled public write access.
The following user(s) said Thank You: VeCrea, BTB300, edwardcox

Re: Two information in a combobox 21 Nov 2012 00:19 #5522

  • VeCrea
  • VeCrea's Avatar
  • Offline
  • Platinum Member
  • Absolute JCook fan
  • Posts: 473
  • Thank you received: 100
  • Karma: 30
Is it still possible in v2 ? Just lost an hour on it... Was so simple
The administrator has disabled public write access.

Re: Two information in a combobox 21 Nov 2012 07:07 #5526

  • mark d
  • mark d's Avatar
You can do this very simply. First, you need to override ToString() in your BankAccount class, which you can do by adding this method to the class:

public override string ToString() {
return self.CustomerName;
}

Then add the BankAccount objects as BankAccount objects (instead of adding their GetName() value as a string):

private void AddToComboBox()
{
cboAccount.Items.Clear();
foreach (BankAccount person in account)
{
//cboAccount.Items.Add(person.GetName());
cboAccount.Items.Add(person);
}
}
The administrator has disabled public write access.

Re: Two information in a combobox 21 Nov 2012 08:39 #5538

  • JoomGuy
  • JoomGuy's Avatar
  • Offline
  • Moderator
  • Joomla Enthusiast, Lover of Cooking
  • Posts: 1115
  • Thank you received: 195
  • Karma: 64
@mark e,

Once again, please refrain from posting this stuff that is not relevant. We appreciate input from all users here, as long as it is relevant to the question, COOK and/or Joomla. This is not a general development forum. Except for a couple of developer sections/categories, the forum is exclusively for COOK & joomla related issues.

Of course, occasionally, some more general PHP, JS and server configuration options have to be suggested when all other avenues have been exhausted however, wherever possible, solutions should pertain to cook, joomla and JS (jQuery or Mootools) functionalities.

Thanks,

Gez
Need help with your Cook/Joomla Project? . PM me to find out what I can help with. NO time wasters please!!!
The administrator has disabled public write access.

Re: Two information in a combobox 21 Nov 2012 08:42 #5539

  • VeCrea
  • VeCrea's Avatar
  • Offline
  • Platinum Member
  • Absolute JCook fan
  • Posts: 473
  • Thank you received: 100
  • Karma: 30
Well I'm happy to see i'm not the only one not finding it relevant... I didn't answer right away because i didn't want to be rude...
I'd be glad to hear from admin or you on this stuff anyway
Thanks,
V.
The administrator has disabled public write access.
The following user(s) said Thank You: JoomGuy

Re: Two information in a combobox 21 Nov 2012 16:26 #5581

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 984
  • Karma: 140
@mark d
We are dealing with PHP, not javascript here.

The tip you are showing is some how great, but why to make it so complex ?

@VeCrea :
Not working anymore ? Strange..
Coding is now a piece of cake
The administrator has disabled public write access.

Re: Two information in a combobox 21 Nov 2012 16:29 #5582

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 984
  • Karma: 140
Maybe a confusion because, the link is not instancied automatically with JDom. It is the forum board wich is adding a link.

But you should be able to create a '<a>' tag as well. No problem at all.

So, are you saying it is not working in combos ?
Coding is now a piece of cake
The administrator has disabled public write access.

Re: Two information in a combobox 21 Nov 2012 16:57 #5591

  • VeCrea
  • VeCrea's Avatar
  • Offline
  • Platinum Member
  • Absolute JCook fan
  • Posts: 473
  • Thank you received: 100
  • Karma: 30
Yes it doesn't.
I need this list to show more than just the labelkey i predefined in the builder.
This list, eg, shows the name of a dish, grouped by season. I would like to be able to show more than the dish name, but also the date where it was last used next to the dish.
$field = $fieldSet['jform_p11'];
$field->jdomOptions = array(
			'list' => $this->lists['fk']['p11'],
			'groupBy' => array(
					'saison' => '_saison_saison'
				)
		);
?>
In the xml file found in models/forms folder, I found that label key for this list is 'name', which seems obvious.
So i tried <%name%> <%modification_date%> but it doesn't work
labelKey="<%name%> <%modification_date%>"
Last Edit: 21 Nov 2012 16:58 by VeCrea.
The administrator has disabled public write access.

Re: Two information in a combobox 26 Nov 2012 21:42 #5649

  • JoomGuy
  • JoomGuy's Avatar
  • Offline
  • Moderator
  • Joomla Enthusiast, Lover of Cooking
  • Posts: 1115
  • Thank you received: 195
  • Karma: 64
Hi @admin

This isn't working for me either... Please could you give us an exact how to?

many thanks,

Gez
Need help with your Cook/Joomla Project? . PM me to find out what I can help with. NO time wasters please!!!
The administrator has disabled public write access.

Re: Two information in a combobox 27 Nov 2012 08:52 #5653

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 984
  • Karma: 140
Yes, In facts, I've just seen it now.

The problem is not JDom but the XML form.

In facts, the '<...>' are not handled.

So for the moment, send your labelKey. in the dynamic options (same than the method used by FK)

In the top of your form template file :
After :
<?php $fieldSet = $this->form->getFieldset('produit.{form_alias}');?>
Write :
$fieldSet['jform_p11']->jdomOptions = array(
	'labelKey' => '<%name%> <%modification_date%>'
);
Coding is now a piece of cake
The administrator has disabled public write access.
The following user(s) said Thank You: cefnllys, JoomGuy

Re: Two information in a combobox 28 Nov 2012 09:44 #5662

  • JoomGuy
  • JoomGuy's Avatar
  • Offline
  • Moderator
  • Joomla Enthusiast, Lover of Cooking
  • Posts: 1115
  • Thank you received: 195
  • Karma: 64
Hi @admin,

Sorry, I cannot get this to work! Please find below my code from the _form for the field in question.
$field = $fieldSet['jform_finish'];
$field->jdomOptions = array(
			'ajaxVars' => array('values' => array(
				$this->item->finish
				));
I'm trying to get the '<%title%> (<%alias%>)' of the finish by adding as you suggest but cannot get it to work.

******ADD*******
I've added:
$field = $fieldSet['jform_finish']->jdomOptions = array(
	'labelKey' => '<%title%> <%alias%>'
);
to the top of my _form file but still no luck! :blush: Am I missing something really obvious here?
******END*******

Please could you demonstrate exactly how in the context of the standard exploded fieldset code above?

Many thanks,

Gez
Need help with your Cook/Joomla Project? . PM me to find out what I can help with. NO time wasters please!!!
Last Edit: 28 Nov 2012 10:25 by JoomGuy. Reason: ADD
The administrator has disabled public write access.

Re: Two information in a combobox 28 Nov 2012 10:44 #5664

  • JoomGuy
  • JoomGuy's Avatar
  • Offline
  • Moderator
  • Joomla Enthusiast, Lover of Cooking
  • Posts: 1115
  • Thank you received: 195
  • Karma: 64
@admin,

This is meant to work in a grid too, right? I'm trying to render the title of the FK with it's alias in parentheses just as a test but I cannot get it working there either.
<?php echo JDom::_('html.fly', array(
	'dataKey' => '<%title%> (<%alias%>)',
	'dataObject' => $row,
	'link_title' => $row->title,
	'route' => array('view' => 'finish','layout' => 'finish','cid[]' => $row->finish)
));
Please, any help with this would be much appreciated! AS I said before, I'm sure I'm missing something obvious...

******ADD 1********
Also, I wonder, can these <%placeholders%> be used to get the name of a foreign object so that we can set the correct title of the item in a link? To precise this, I mean in the 'link_title' element so, rather than only being able to use the name/title of the object we're clicking on OR the foreign key itself.... ;)

****EDIT***
Sorry,audibleid wrote:
I wonder, can these <%placeholders%> be used to get the name of a foreign object so that we can set the correct title of the item in a link?
that's straight forward using the _foreigntable_field format so in a grid but would be super nice to concat other details from FK table to be more descriptive!:
....
'link_title' => $row->_table_field,'
**************
**********************

Thanks in advance,

Gez
Need help with your Cook/Joomla Project? . PM me to find out what I can help with. NO time wasters please!!!
Last Edit: 28 Nov 2012 11:10 by JoomGuy. Reason: EDITED my last add
The administrator has disabled public write access.
Time to create page: 0.166 seconds

Get Started