5

Not much explanation found for the predefinedlist form field at https://docs.joomla.org/Standard_form_field_types

Can someone please help me how this can be configured?

3

predefinedlist form field is extending ordinary list field. It allows to create drop downs with predefined options (as name says). Also allowing to add custom options through XML.

For example it's used by status, userstate and useractive field types (also not documented). These are mainly used by Joomla! Core extensions.

I think that lack of documentation for these fields is caused by extending list field. In the end, these fields are ordinary list fields.

Take a look at status field source code.

<?php
/**
 * @package     Joomla.Libraries
 * @subpackage  Form
 *
 * @copyright   Copyright (C) 2005 - 2015 Open Source Matters, Inc. All rights reserved.
 * @license     GNU General Public License version 2 or later; see LICENSE
 */

defined('JPATH_PLATFORM') or die;

JFormHelper::loadFieldClass('predefinedlist');

/**
 * Form Field to load a list of states
 *
 * @since  3.2
 */
class JFormFieldStatus extends JFormFieldPredefinedList
{
    /**
     * The form field type.
     *
     * @var    string
     * @since  3.2
     */
    public $type = 'Status';

    /**
     * Available statuses
     *
     * @var  array
     * @since  3.2
     */
    protected $predefinedOptions = array(
        '-2' => 'JTRASHED',
        '0'  => 'JUNPUBLISHED',
        '1'  => 'JPUBLISHED',
        '2'  => 'JARCHIVED',
        '*'  => 'JALL'
    );
}

As you can see, it just adds Joomla! Core statuses to protected $predefinedOptions.

JFormFieldPredefinedList (source) extends JFormFieldList (source) and its only purpose is to add options without adding them through XML. These items are now added to regular list field as options.

In custom component it allows to add more options (statuses) if needed, avoiding possibility to remove necessary items. And of course, you can create you own custom field and extend it from JFormFieldPredefinedList.

This XML is from Content component (com_content) articles view status filter. As said before, status field extends predefinedlist field.

<field
    name="published"
    type="status"
    label="COM_CONTENT_FILTER_PUBLISHED"
    description="COM_CONTENT_FILTER_PUBLISHED_DESC"
    onchange="this.form.submit();"
    >
    <option value="">JOPTION_SELECT_PUBLISHED</option>
</field>

Result:

enter image description here

It adds only one option, which is "- Select Status -" (first default option). All other options are predefined from JFormFieldStatus class property $predefinedOptions. You couldn't remove or edit them through XML.

Basically, predefinedlist form field (JFormFieldPredefinedList class) is used to protect some certain options, what field must definitely have. It is not intended to be used as stand-alone field.

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.