J1.5 talk

Difference between revisions of "Adding a multiple item select list parameter type"

From Joomla! Documentation

 
(5 intermediate revisions by 3 users not shown)
Line 6: Line 6:
  
 
Any ideas for a fix?????????????????
 
Any ideas for a fix?????????????????
 +
 +
 +
Line with $value is unnecessary - when you select more than one items then it returns array in array. I've removed this line from the source code - now it should works fine.
 +
 +
 +
I needed this
 +
 +
    function fetchElement($name, $value, &$node, $control_name) {
 +
   
 +
        (...)
 +
   
 +
        // value string to array
 +
        $value = explode(',', $value);
 +
   
 +
        return JHTML::_('select.genericlist', $options, $ctrl, $attribs, 'value', 'text', $value, $control_name . $name);
 +
    }
 +
 +
== multiple "categories" ==
 +
 +
in joomla 1.6 and above, the category param allows to choice only one selection.
 +
 +
if you need more than one choice, how can to do it?
 +
 +
 +
<source lang="xml">
 +
<field
 +
  name="Categorias"
 +
  type="category"
 +
  extension="com_content"
 +
  show_root="1"
 +
  label="Lista de categorías"
 +
  default=""
 +
</source>
 +
the multiple param must be:
 +
'''multiple="multiple"'''
 +
and close the field element
 +
<source lang="xml">
 +
/>
 +
</source>

Latest revision as of 21:47, 7 June 2013

I tried this code in my application and it almost worked but not exactly.

When I selected more than one item, the parameter was saved in the database as: p1|p2 rather than p1,p2 as would be the normal case of html.

If I then go to the database and change it manually to p1,p2; then it displayed correctly in the administrator..

Any ideas for a fix?????????????????


Line with $value is unnecessary - when you select more than one items then it returns array in array. I've removed this line from the source code - now it should works fine.


I needed this

   function fetchElement($name, $value, &$node, $control_name) {
   
       (...)
   
       // value string to array
       $value = explode(',', $value);
   
       return JHTML::_('select.genericlist', $options, $ctrl, $attribs, 'value', 'text', $value, $control_name . $name);
   }

multiple "categories"[edit]

in joomla 1.6 and above, the category param allows to choice only one selection.

if you need more than one choice, how can to do it?


<field
			   name="Categorias"
			   type="category"
			   extension="com_content"
			   show_root="1"
			   label="Lista de categorías"
			   default=""

the multiple param must be: multiple="multiple" and close the field element

/>