<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="http://docs.joomla.org/skins/common/feed.css?303"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://docs.joomla.org/index.php?title=Adding_a_multiple_item_select_list_parameter_type&amp;feed=atom&amp;action=history</id>
		<title>Adding a multiple item select list parameter type - Revision history</title>
		<link rel="self" type="application/atom+xml" href="http://docs.joomla.org/index.php?title=Adding_a_multiple_item_select_list_parameter_type&amp;feed=atom&amp;action=history"/>
		<link rel="alternate" type="text/html" href="http://docs.joomla.org/index.php?title=Adding_a_multiple_item_select_list_parameter_type&amp;action=history"/>
		<updated>2013-05-22T20:45:03Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.19.3</generator>

	<entry>
		<id>http://docs.joomla.org/index.php?title=Adding_a_multiple_item_select_list_parameter_type&amp;diff=30870&amp;oldid=prev</id>
		<title>Batch1211 at 09:07, 20 September 2010</title>
		<link rel="alternate" type="text/html" href="http://docs.joomla.org/index.php?title=Adding_a_multiple_item_select_list_parameter_type&amp;diff=30870&amp;oldid=prev"/>
				<updated>2010-09-20T09:07:20Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class='diff diff-contentalign-left'&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
			&lt;tr valign='top'&gt;
			&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;← Older revision&lt;/td&gt;
			&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;Revision as of 09:07, 20 September 2010&lt;/td&gt;
			&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 162:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 162:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;* [[Custom parameter types]]&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;* [[Custom parameter types]]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;lt;noinclude&amp;gt;[[Category:Development]][[Category:Parameters]]&amp;lt;/noinclude&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;lt;noinclude&amp;gt;[[Category:Development]][[Category:Parameters]]&amp;lt;/noinclude&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;[[Category:Tutorials]][[Category:Component Development]]&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Batch1211</name></author>	</entry>

	<entry>
		<id>http://docs.joomla.org/index.php?title=Adding_a_multiple_item_select_list_parameter_type&amp;diff=20505&amp;oldid=prev</id>
		<title>Dziudek: Fixed problem with selecting more than one item</title>
		<link rel="alternate" type="text/html" href="http://docs.joomla.org/index.php?title=Adding_a_multiple_item_select_list_parameter_type&amp;diff=20505&amp;oldid=prev"/>
				<updated>2009-11-29T00:10:29Z</updated>
		
		<summary type="html">&lt;p&gt;Fixed problem with selecting more than one item&lt;/p&gt;
&lt;table class='diff diff-contentalign-left'&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
			&lt;tr valign='top'&gt;
			&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;← Older revision&lt;/td&gt;
			&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;Revision as of 00:10, 29 November 2009&lt;/td&gt;
			&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 66:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 66:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;			$ctrl		.= '[]';&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;			$ctrl		.= '[]';&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;		}&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;		}&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;		// Convert the comma-separated list of values to an array.&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;		$value = explode( ',', $value );&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;		// Render the HTML SELECT list.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;		// Render the HTML SELECT list.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Dziudek</name></author>	</entry>

	<entry>
		<id>http://docs.joomla.org/index.php?title=Adding_a_multiple_item_select_list_parameter_type&amp;diff=14821&amp;oldid=prev</id>
		<title>Chris Davenport: New page: The standard list parameter type does not support selection of multiple items in Joomla 1.5.x. However, it is quite straightforward to add an additional custom para...</title>
		<link rel="alternate" type="text/html" href="http://docs.joomla.org/index.php?title=Adding_a_multiple_item_select_list_parameter_type&amp;diff=14821&amp;oldid=prev"/>
				<updated>2009-07-01T22:31:48Z</updated>
		
		<summary type="html">&lt;p&gt;New page: The standard &lt;a href=&quot;/index.php?title=List_parameter_type&amp;amp;action=edit&amp;amp;redlink=1&quot; class=&quot;new&quot; title=&quot;List parameter type (page does not exist)&quot;&gt;list parameter type&lt;/a&gt; does not support selection of multiple items in Joomla 1.5.x. However, it is quite straightforward to add an additional custom para...&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;The standard [[List parameter type|list parameter type]] does not support selection of multiple items in Joomla 1.5.x.&lt;br /&gt;
However, it is quite straightforward to add an additional custom parameter type with this&lt;br /&gt;
functionality to any component or module.  Note that this is not required for Joomla 1.6.x as that&lt;br /&gt;
version supports multiple selection lists natively.&lt;br /&gt;
&lt;br /&gt;
The code to support the custom parameter is in two parts.  A single file containing all the code&lt;br /&gt;
required to render the HTML SELECT list and a small piece of additional code to be added to whatever&lt;br /&gt;
code processes the FORM after submission by the user.  This could, for example, be the bind() method&lt;br /&gt;
if the value(s) are being stored in a database table.  In addition, you will want to add one or&lt;br /&gt;
more &amp;lt;param&amp;gt; elements to the XML file which defines the form where the SELECT list is to be added.&lt;br /&gt;
&lt;br /&gt;
==Rendering the parameter==&lt;br /&gt;
The code required to render the multiple item select list is here:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
/**&lt;br /&gt;
* @copyright	Copyright (C) 2009 Open Source Matters. All rights reserved.&lt;br /&gt;
* @license	GNU/GPL&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
// Check to ensure this file is within the rest of the framework&lt;br /&gt;
defined('JPATH_BASE') or die();&lt;br /&gt;
&lt;br /&gt;
/**&lt;br /&gt;
 * Renders a multiple item select element&lt;br /&gt;
 *&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
class JElementMultiList extends JElement&lt;br /&gt;
{&lt;br /&gt;
	/**&lt;br /&gt;
	* Element name&lt;br /&gt;
	*&lt;br /&gt;
	* @access	protected&lt;br /&gt;
	* @var		string&lt;br /&gt;
	*/&lt;br /&gt;
	var	$_name = 'MultiList';&lt;br /&gt;
&lt;br /&gt;
	function fetchElement($name, $value, &amp;amp;$node, $control_name)&lt;br /&gt;
	{&lt;br /&gt;
		// Base name of the HTML control.&lt;br /&gt;
		$ctrl	= $control_name .'['. $name .']';&lt;br /&gt;
&lt;br /&gt;
		// Construct an array of the HTML OPTION statements.&lt;br /&gt;
		$options = array ();&lt;br /&gt;
		foreach ($node-&amp;gt;children() as $option)&lt;br /&gt;
		{&lt;br /&gt;
			$val	= $option-&amp;gt;attributes('value');&lt;br /&gt;
			$text	= $option-&amp;gt;data();&lt;br /&gt;
			$options[] = JHTML::_('select.option', $val, JText::_($text));&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		// Construct the various argument calls that are supported.&lt;br /&gt;
		$attribs	= ' ';&lt;br /&gt;
		if ($v = $node-&amp;gt;attributes( 'size' )) {&lt;br /&gt;
			$attribs	.= 'size=&amp;quot;'.$v.'&amp;quot;';&lt;br /&gt;
		}&lt;br /&gt;
		if ($v = $node-&amp;gt;attributes( 'class' )) {&lt;br /&gt;
			$attribs	.= 'class=&amp;quot;'.$v.'&amp;quot;';&lt;br /&gt;
		} else {&lt;br /&gt;
			$attribs	.= 'class=&amp;quot;inputbox&amp;quot;';&lt;br /&gt;
		}&lt;br /&gt;
		if ($m = $node-&amp;gt;attributes( 'multiple' ))&lt;br /&gt;
		{&lt;br /&gt;
			$attribs	.= ' multiple=&amp;quot;multiple&amp;quot;';&lt;br /&gt;
			$ctrl		.= '[]';&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		// Convert the comma-separated list of values to an array.&lt;br /&gt;
		$value = explode( ',', $value );&lt;br /&gt;
&lt;br /&gt;
		// Render the HTML SELECT list.&lt;br /&gt;
		return JHTML::_('select.genericlist', $options, $ctrl, $attribs, 'value', 'text', $value, $control_name.$name );&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
This should be saved in a file called ''multilist.php'' in a separate directory within your component or module directory.  It&lt;br /&gt;
is recommended that for consistency this directory is called ''elements'', but this is not required.&lt;br /&gt;
For example, if you want to add support for this field into a component called ''mycomponent'', then you would copy-paste the above code&lt;br /&gt;
into this file:&lt;br /&gt;
&amp;lt;pre&amp;gt;/administrator/components/com_mycomponent/elements/multilist.php&amp;lt;/pre&amp;gt;&lt;br /&gt;
Don't forget to add an empty ''index.html'' file into the ''elements'' directory to prevent directory listing.&lt;br /&gt;
&lt;br /&gt;
==Adding the element to a form==&lt;br /&gt;
Parameters are rendered using form definition information contained in an XML file.  For example, for a component this file will&lt;br /&gt;
typically be:&lt;br /&gt;
&amp;lt;pre&amp;gt;/administrator/components/com_mycomponent/config.xml&amp;lt;/pre&amp;gt;&lt;br /&gt;
In this file, you should add one or more selection list parameters by adding a &amp;lt;param&amp;gt; element into an appropriate &amp;lt;params&amp;gt;&lt;br /&gt;
parameter group, like this:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;param name=&amp;quot;field-name&amp;quot; type=&amp;quot;multilist&amp;quot; default=&amp;quot;OPT1&amp;quot; multiple=&amp;quot;multiple&amp;quot; label=&amp;quot;Select one or more items&amp;quot;&lt;br /&gt;
 description=&amp;quot;Select one or more items from the list.  You can use Ctrl-click to select more than one item.&amp;quot;&amp;gt;&lt;br /&gt;
	&amp;lt;option value=&amp;quot;OPT1&amp;quot;&amp;gt;Title for option 1&amp;lt;/option&amp;gt;&lt;br /&gt;
	&amp;lt;option value=&amp;quot;OPT2&amp;quot;&amp;gt;Title for option 2&amp;lt;/option&amp;gt;&lt;br /&gt;
	&amp;lt;option value=&amp;quot;OPT3&amp;quot;&amp;gt;Title for option 3&amp;lt;/option&amp;gt;&lt;br /&gt;
	&amp;lt;option value=&amp;quot;OPT4&amp;quot;&amp;gt;Title for option 4&amp;lt;/option&amp;gt;&lt;br /&gt;
	&amp;lt;option value=&amp;quot;OPT5&amp;quot;&amp;gt;Title for option 5&amp;lt;/option&amp;gt;&lt;br /&gt;
&amp;lt;/param&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
The arguments are as follows:&lt;br /&gt;
&lt;br /&gt;
* '''type''' (mandatory) must be ''multilist''.&lt;br /&gt;
* '''name''' (mandatory) is the unique name of the parameter.&lt;br /&gt;
* '''label''' (mandatory) (translatable) is the descriptive title of the field.&lt;br /&gt;
* '''default''' (optional) is a comma-separated list of default values.&lt;br /&gt;
* '''size''' (optional) is the number of option rows that will be visible in the list.  If omitted, all rows will be displayed.&lt;br /&gt;
* '''description''' (optional) (translatable) is text that will be shown as a tooltip when the user moves the mouse over the drop-down box.&lt;br /&gt;
* '''class''' (optional) is a CSS class name for the HTML form field.  If omitted this will default to 'inputbox'.&lt;br /&gt;
* '''multiple''' (optional) indicates whether the field will allow more than one option row to be selected.  The should always be set to &amp;quot;multiple&amp;quot; since if it isn't you might as well use the standard [[List parameter type|list parameter type]].&lt;br /&gt;
&lt;br /&gt;
The XML &amp;lt;tt&amp;gt;&amp;lt;param&amp;gt;&amp;lt;/tt&amp;gt; element must include one or more &amp;lt;tt&amp;gt;&amp;lt;option&amp;gt;&amp;lt;/tt&amp;gt; elements which define the list items.  The text between the &amp;lt;tt&amp;gt;&amp;lt;option&amp;gt;&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;&amp;lt;/option&amp;gt;&amp;lt;/tt&amp;gt; tags is what will be shown in the option list and is a translatable string.  The &amp;lt;option&amp;gt; tag takes the following argument:&lt;br /&gt;
&lt;br /&gt;
* '''value''' (mandatory) is the value that will be saved for the parameter if this item is selected.&lt;br /&gt;
&lt;br /&gt;
Since this is a custom parameter type, you will also need to tell Joomla where to find the code to render the parameter.  You&lt;br /&gt;
do this by adding an ''addPath'' argument to the containing &amp;lt;params&amp;gt; element.  For example, to add a parameter group containing&lt;br /&gt;
just a single multiple element selection list to your component, the XML would look like this:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;params group=&amp;quot;group-name&amp;quot; addPath=&amp;quot;/administrator/components/com_mycomponent/elements&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
	&amp;lt;param name=&amp;quot;field-name&amp;quot; type=&amp;quot;multilist&amp;quot; default=&amp;quot;OPT1&amp;quot; multiple=&amp;quot;multiple&amp;quot; label=&amp;quot;Select one or more items&amp;quot;&lt;br /&gt;
 description=&amp;quot;Select one or more items from the list.  You can use Ctrl-click to select more than one item.&amp;quot;&amp;gt;&lt;br /&gt;
		&amp;lt;option value=&amp;quot;OPT1&amp;quot;&amp;gt;Title for option 1&amp;lt;/option&amp;gt;&lt;br /&gt;
		&amp;lt;option value=&amp;quot;OPT2&amp;quot;&amp;gt;Title for option 2&amp;lt;/option&amp;gt;&lt;br /&gt;
		&amp;lt;option value=&amp;quot;OPT3&amp;quot;&amp;gt;Title for option 3&amp;lt;/option&amp;gt;&lt;br /&gt;
		&amp;lt;option value=&amp;quot;OPT4&amp;quot;&amp;gt;Title for option 4&amp;lt;/option&amp;gt;&lt;br /&gt;
		&amp;lt;option value=&amp;quot;OPT5&amp;quot;&amp;gt;Title for option 5&amp;lt;/option&amp;gt;&lt;br /&gt;
	&amp;lt;/param&amp;gt;&lt;br /&gt;
&amp;lt;/params&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Only a single ''addPath'' argument is permitted per parameter group which is why it's a good idea to gather all your custom&lt;br /&gt;
parameter code into a single ''elements'' directory.&lt;br /&gt;
&lt;br /&gt;
==Saving parameter values to a database==&lt;br /&gt;
The most common use for this custom parameter type will involve saving whatever values the user selected into a field in&lt;br /&gt;
a database table.  Assuming you are doing this using the [[JTable]] API class, then you will need to add the following code&lt;br /&gt;
to the [[JTable]] extended class for the appropriate table.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
    /**&lt;br /&gt;
     * Overloaded bind function&lt;br /&gt;
     *&lt;br /&gt;
     * @param array $array  Array or object of values to bind&lt;br /&gt;
     * @param mixed $ignore Array or space separated list of fields not to bind&lt;br /&gt;
     *&lt;br /&gt;
     * @return null|string Success returns null, failure returns an error&lt;br /&gt;
     * @access public&lt;br /&gt;
     * @see    JTable:bind&lt;br /&gt;
     */&lt;br /&gt;
    function bind( $array, $ignore = '' )&lt;br /&gt;
    {&lt;br /&gt;
        if (key_exists( 'field-name', $array ) &amp;amp;&amp;amp; is_array( $array['field-name'] )) {&lt;br /&gt;
	        $array['field-name'] = implode( ',', $array['field-name'] );&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        return parent::bind( $array, $ignore );&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Note that ''field-name'' must match the name you gave the field in the XML form definition file and the&lt;br /&gt;
name given to the database field.&lt;br /&gt;
&lt;br /&gt;
Using this code the data will be stored as a comma-separated list of values in the database field.  To use a different&lt;br /&gt;
separator, change the comma to whatever character you want to use in the ''implode'' function call in the ''bind()'' method&lt;br /&gt;
and the corresponding ''explode'' function call in the ''multilist.php'' file.&lt;br /&gt;
===See also===&lt;br /&gt;
* [[Custom parameter types]]&lt;br /&gt;
&amp;lt;noinclude&amp;gt;[[Category:Development]][[Category:Parameters]]&amp;lt;/noinclude&amp;gt;&lt;/div&gt;</summary>
		<author><name>Chris Davenport</name></author>	</entry>

	</feed>