How to use <xen:selectunit> ?

It's all there in the existing code.

The user_edit template has loads of examples.

There's these:

Code:
                <xen:selectunit label="{xen:phrase user_state}:" name="user_state" value="{$user.user_state}">
                    <xen:option value="valid">{xen:phrase valid}</xen:option>
                    <xen:option value="email_confirm">{xen:phrase awaiting_email_confirmation}</xen:option>
                    <xen:option value="email_confirm_edit">{xen:phrase awaiting_email_confirmation_from_edit}</xen:option>
                    <xen:option value="moderated">{xen:phrase awaiting_approval}</xen:option>
                </xen:selectunit>

But there's also this type:

Code:
                <xen:checkboxunit label="{xen:phrase secondary_user_groups}:" name="secondary_group_ids" class="checkboxColumns">
                    <xen:options source="$secondaryGroups" />
                </xen:checkboxunit>

Where $secondaryGroups is an array passed to the template as a view parameter. It should be in this format:

PHP:
$secondaryGroups = array(
     'some_value' => array(
          'value' => 'some_value',
          'label' => new XenForo_Phrase('some_phrase')
     ),
     'some_other_value' => array(
          'value' => 'some_other_value',
          'label' => new XenForo_Phrase('some_other_phrase')
     )
);
 
I tried using the first one (in a xen:foreach tag), but the select was being closed just before the options were printed.

<xen:options> produces an error saying there isn't a tag called options...
 
Last edited:
You wouldn't normally use a loop to create a select unit, but you could use a loop inside a select unit to render the options.
Code:
                <xen:selectunit label="{xen:phrase user_state}:" name="user_state" value="{$user.user_state}">
                    <xen:foreach loop="$options" key="$value" value="$text">
                         <xen:option value="{$value}">{$text}</xen:option>
                    </xen:foreach>
                </xen:selectunit>
 
You wouldn't normally use a loop to create a select unit, but you could use a loop inside a select unit to render the options.
Code:
                <xen:selectunit label="{xen:phrase user_state}:" name="user_state" value="{$user.user_state}">
                    <xen:foreach loop="$options" key="$value" value="$text">
                         <xen:option value="{$value}">{$text}</xen:option>
                    </xen:foreach>
                </xen:selectunit>
I tried that, but the <option> tags were appearing after the </select> tag, resulting in no options...
 
Then you were doing something wrong.

If you provide the code you were using it will be easier to debug.
 
Top Bottom