1

I'm building a Joomla component and want a specific field (listtype) in component. In administrator/component/com_test/models/forms/testfield.xml I've following code:

<field
  name="test"
  type="testfield"
  label="JOPTION_FILTER_TESTFIELD_LABEL"
  description="JOPTION_FILTER_TESTFIELD_DESC"
  id="testfield"
  class="inputbox"
/>

In administrator/component/com_test/models/fields/testfield.php I've following code:

JFormHelper::loadFieldClass('list');

/**
 * Test Field class.
 */

class JFormFieldTestField extends JFormField {

    protected $type = 'TestField';

    public function getInput() {
        return '<select id="'.$this->id.'" name="'.$this->name.'">'.
               '<option value="">select test</option>'.
               '<option value="1">test1</option>'.
               '<option value="2">test2</option>'.
               '<option value="3">test3</option>'.
               '</select>';
   }
}

In administrator/component/com_test/views/tests/tmpl/default.php I've created a column 'test':

<td class="small hidden-phone">
    <?php   echo $item->test; ?>
</td>

I've a problem to save data 1,2,3 to database and second I want that in stead of the values 1,2,3 as saved into the database, the values ‘test1’, ‘test2’, ‘test3’ will be reproduced in this column. I've tried several things (e.g. with JTEXT in 'testfield.php'), but until now I didn't manage to find the correct code. Can anyone help me further?

1

You need to put that field into the params fieldset, have a look how com_content did it. Then you need to do $item->params->get('test');

I would also extend from JFormFieldList and then override the getOptions function, then ill be the select generated automatically.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.