Joomla list Form Field Type

The list form field type provides a drop down list or a list box of custom-defined entries. If the field has a saved value this is selected when the page is first loaded. If not, the default value (if any) is selected.

The XML <field> element must include one or more <option> elements which define the list items. The text between the <option> and </option> tags is what will be shown in the drop down list and is a translatable string. The value argument of the <option> tag is the value that will be saved for the field if this item is selected. Don't forget to close the field definition with </field>.

Field Definition

XML field definition:

<field name="mylistvalue" type="list" default="" label="Select an option" description="">
<option value="0">Option 1</option>
<option value="1">Option 2</option>
</field>

XML field definition with required field value:

<field name="mylistvalue" type="list" default="" required="true" label="Select an option" description="">
<option value="">Please Select</option>
<option value="0">Option 1</option>
<option value="1">Option 2</option>
</field>

Add first an option without a value, with a text like "Select an option". Otherwise, in case of a required field, the first option with a value gets silently selected (without the user choosing it). This text will typically be seen by users before clicking the drop down list.

Mandatory Parameters

  • type must be list.

  • name is the unique name of the field.

  • label (translatable) is the descriptive title of the field.

Optional Parameters

  • default is the default list item value.

  • description (translatable) is text that will be shown as a tooltip when the user moves the mouse over the drop-down box.

  • class is a CSS class name for the HTML form field. If omitted this will default to 'inputbox'.

  • multiple is whether multiple items can be selected at the same time (true or false).

  • required: if set to true, the first field option should be empty.

  • useglobal: if set to true, it will show the value that is set in the global configuration if found in the database.

Examples

State Field (com_content)

<field
name="state"
type="list"
label="JSTATUS"
description="JFIELD_PUBLISHED_DESC"
class="chzn-color-state"
filter="intval"
size="1"
default="1"
>
<option value="1">JPUBLISHED</option>
<option value="0">JUNPUBLISHED</option>
<option value="2">JARCHIVED</option>
<option value="-2">JTRASHED</option>
</field>

Show Title Field (com_content)

<field
name="show_title"
type="list"
label="JGLOBAL_SHOW_TITLE_LABEL"
description="JGLOBAL_SHOW_TITLE_DESC"
class="chzn-color"
useglobal="true"
>
<option value="1">JSHOW</option>
<option value="0">JHIDE</option>
</field>

Link Target Field (com_content)

<field
name="targeta"
type="list"
label="COM_CONTENT_URL_FIELD_BROWSERNAV_LABEL"
description="COM_CONTENT_URL_FIELD_BROWSERNAV_DESC"
default=""
filter="options"
useglobal="true"
>
<option value="0">JBROWSERTARGET_PARENT</option>
<option value="1">JBROWSERTARGET_NEW</option>
<option value="2">JBROWSERTARGET_POPUP</option>
<option value="3">JBROWSERTARGET_MODAL</option>
</field>

 

Star InactiveStar InactiveStar InactiveStar InactiveStar Inactive