Search code examples
joomlaform-fields

How to set multiple default values in a groupedlist type form field in joomla


I'm creating my own template and I need to set multiple default values for a groupedlist type form field.

What i did:

<field name="grid-top" 
       type="groupedlist" 
       label="COM_TPL_MYTEMPLATE_DIV_TYPE_LABEL" 
       description="COM_TPL_MYTEMPLATE_DIV_TYPE_DESC"
       multiple="true" 
       class="big"
       default="VALUE-1, VALUE-2" />

however this way doesnt work. anyone please point me to a right direction, How can i set multiple default values ?


Solution

  • The default value in the xml should be a JSON Encoded array.

    So your XML should show as this:

    <field name="grid-top" 
           type="groupedlist" 
           label="COM_TPL_MYTEMPLATE_DIV_TYPE_LABEL" 
           description="COM_TPL_MYTEMPLATE_DIV_TYPE_DESC"
           multiple="true" 
           class="big"
           default='["VALUE-1","VALUE-2"]' />
    

    Also note that values must be protected by a double quote so you need to use a single quote to encalsulate the whole default value. Using default="['VALUE-1','VALUE-2']" would not work.