2

I have added a dropdown list to my user creation form in admin panel in Joomla! 1.5 (using .xml files). The problem I have is that the content of it must be dynamic (comes from an external source file). My question is where (and possibly how) I can make it.

Techie
  • 44,706
  • 42
  • 157
  • 243
Ziker
  • 141
  • 4
  • 20

3 Answers3

2

you can create your own type. At your default.xml you will have something like:

<url addpath="/administrator/components/com_componentname/elements/">
    <param name="id" type="myType" default="0" label="SELECT_LABEL" description="SELECT_DESC" />
</url>

and as implementation in /administrato/components/com_componentname/elements/myType.php

class JElementmyType extends JElement {
    var     $_name = 'myType';

    function fetchElement($name, $value, &$node, $control_name)
    {

            $list = READ_FILE_OR_DB_OR_ANYTHING();
            array_unshift($list, JHTML::_('select.option', '0', '-'.JText::_('Select Me').' -', 'value', 'text'));

            return JHTML::_('select.genericlist',  $list, ''.$control_name.'['.$name.']', 'class="inputbox"', 'value', 'text', $value, $control_name.$name );
    }

}

Fusselchen
  • 382
  • 1
  • 4
  • 12
  • Ohh, this is exactly what I am looking for, could You also tell me what format does $list array have? Would be lovely. Many thanks anyway! – Ziker Jan 21 '13 at 09:58
  • It is an array of `JModel`, normally returned by a Databasequery. But you can use your own function to create the objects – Fusselchen Jan 21 '13 at 14:43
  • I posted my code in the answer - to show the code clearly. Everything explained there as well – Ziker Jan 21 '13 at 20:46
0

You can use sql type field if you are using xml form.

<param name="user" type="sql" default="" label="Select an User" query="SELECT id, username FROM #__user" key_field="id" value_field="username" />

read more - http://docs.joomla.org/Sql_parameter_type

Irfan
  • 7,029
  • 3
  • 42
  • 57
  • Yeah, it would be lovely, but this data is loaded from a .txt file generated by an external application. There is no way to change it. – Ziker Jan 20 '13 at 13:24
0

I have this problem - done just like You told me, my code looks like that:

    <?php

jimport( 'joomla.html.html.select' );

class JElementKlasa extends JElement {
    var     $_name = 'Klasa';

    function fetchElement($name, $value, &$node, $control_name)
    {

            $list = array(1=>'a', 2=>'b');
            $options = array();
            foreach($list as $key=>$value)
                $options[] = JHTML::_('select.option', $key, $value);

            //array_unshift($list, JHTML::_('select.option', '0', "Take it"));

            return JHTML::_('select.genericlist',  $options, 'klas', '', 'value', 'text');
 }

 ?>

but it does not appear there - it actually makes the space for it, but it is empty : ( I will keep trying to fix it in the meantime.

Ziker
  • 141
  • 4
  • 20