XF 2.1 Dropdown menu default option

051119

Member
The helper_action template has been modified so that the forum staff have a predefined dropdown menu from which to select the reason for deleting a post.

I'm trying to set it up so that one of the options in the middle is the default choice. However when I do this by adding selected="selected" I get the error message "Line 59: Syntax error - Template name: public:helper_action."

Can anyone help me please, l'm sure this is standard Html and indeed is how this dropdown appeared on xF 1.5.

Here is an example of the current code.

Code:
                <xf:select name="{$reasonName}" value="Reason">
                     <xf:option value="1 - Reason 1">1 - Reason 1</xf:option>
                    <xf:option value="2 - Reason 2">2 - Reason 2</xf:option>
                    <xf:option value="3 - Reason 3">3 - Reason 3</xf:option>
                    <xf:option value="4 - Reason 4">4 - Reason 4</xf:option>
                    <xf:option value="5 - Reason 5">5 - Reason 5</xf:option>
                 </xf:select>
 
You can use the value attribute at the xf:select tag to define which option is selected.

For example this will select the third option:
Code:
<xf:select name="{$reasonName}" value="3 - Reason 3">
                     <xf:option value="1 - Reason 1">1 - Reason 1</xf:option>
                    <xf:option value="2 - Reason 2">2 - Reason 2</xf:option>
                    <xf:option value="3 - Reason 3">3 - Reason 3</xf:option>
                    <xf:option value="4 - Reason 4">4 - Reason 4</xf:option>
                    <xf:option value="5 - Reason 5">5 - Reason 5</xf:option>
                 </xf:select>

If you're already storing a potential value in a variable and want a fallback default selection, you can do so with the ternary operator and an inline statement:
Code:
<xf:select name="{$reasonName}" value="{{ $myValue ?: '3 - Reason 3' }} ">
                     <xf:option value="1 - Reason 1">1 - Reason 1</xf:option>
                    <xf:option value="2 - Reason 2">2 - Reason 2</xf:option>
                    <xf:option value="3 - Reason 3">3 - Reason 3</xf:option>
                    <xf:option value="4 - Reason 4">4 - Reason 4</xf:option>
                    <xf:option value="5 - Reason 5">5 - Reason 5</xf:option>
                 </xf:select>
 
Top Bottom