Skip to main content

CategoryDuallistboxField

CategoryDuallistboxField extends DuallistboxField and automatically populates the Available panel with all published Joomla com_content categories. Hierarchy is expressed through em-dash indentation. Use it wherever an admin form must let the user assign multiple Joomla categories to a record.

Class Details​

PropertyValue
ClassCategoryDuallistboxField
NamespaceJ2Commerce\Component\J2commerce\Administrator\Field
Fileadministrator/components/com_j2commerce/src/Field/CategoryDuallistboxField.php
ExtendsJoomla\CMS\Form\Field\ListField
Field type stringCategoryDuallistbox
Since6.0.7

Assets Loaded​

Same as DuallistboxField:

AssetTypePath
dual-listbox-scriptJavaScriptmedia/com_j2commerce/js/administrator/dual-listbox.js
dual-listbox-styleCSSmedia/com_j2commerce/css/administrator/dual-listbox.css

Data Source​

getOptions() queries #__categories filtered to extension = 'com_content' and published = 1, ordered by lft ASC (nested set left position) to preserve natural hierarchy. Each category label is prefixed with — repeated (level - 1) times.

SELECT id AS value, title AS text, level
FROM #__categories
WHERE extension = 'com_content'
AND published = 1
ORDER BY lft ASC

Category IDs (integers) are used as option values. Selected values are stored and submitted as an array of category ID strings.

XML Usage​

<form addfieldprefix="J2Commerce\Component\J2commerce\Administrator\Field">
<fieldset name="basic">
<field
name="product_categories"
type="CategoryDuallistbox"
label="COM_J2COMMERCE_FIELD_CATEGORIES"
description="COM_J2COMMERCE_FIELD_CATEGORIES_DESC"
size="12"
/>
</fieldset>
</form>

No <option> children are needed — the field populates itself from the database.

XML Attributes​

AttributeRequiredDefaultDescription
nameYes—Field name. Posted as name[] (array of category IDs).
typeYes—Must be CategoryDuallistbox.
labelYes—Language key for the field label.
descriptionNo—Language key for the field tooltip.
classNoform-selectCSS class for the underlying <select> element.
sizeNo10Visible row count per listbox panel.
disabledNofalseDisables the widget when true.
readonlyNofalseSets the widget to read-only when true.
requiredNofalseRequires at least one selection when true.

Value Handling​

Stored values may be:

  • A PHP array of category ID strings.
  • A comma-separated string of category IDs ("3,7,12").

Both formats are normalised by processValue() before initialising the JavaScript widget.

Error Handling​

If the database query fails, the field enqueues an admin error message using COM_J2COMMERCE_ERROR_LOADING_CATEGORIES and returns only any options defined via XML child elements (typically none).