<xf:checkboxrow
label="{$option.title}"
hint="{$hintHtml}"
explain="{$explainHtml}"
html="{$listedHtml}"
rowclass="{$rowClass}"
listclass="listColumns">
<xf:foreach loop="$groups" value="$group">
<xf:option name="{$inputName}[groups][{$group.value}]" value="{$option.option_value.{$group.value}}">
{{ $group.label }}
</xf:option>
</xf:foreach>
</xf:checkboxrow>
{groups: {"1": "1", "2": "2"}} in backend.{groups: [1, 2]}?<xf:checkboxrow label="{{ phrase('content_options') }}">
<xf:option value="watch_no_email" name="option[creation_watch_state]" checked="{{ $xf.visitor.Option.creation_watch_state ? true : false }}"
label="{{ phrase('automatically_watch_content_you_create...') }}">
<xf:checkbox>
<xf:option value="watch_email" name="option[creation_watch_state]" checked="{{ $xf.visitor.Option.creation_watch_state == 'watch_email' }}"
label="{{ phrase('and_receive_email_notifications') }}" />
</xf:checkbox>
</xf:option>
<xf:option value="watch_no_email" name="option[interaction_watch_state]" checked="{{ $xf.visitor.Option.interaction_watch_state ? true : false }}"
label="{{ phrase('automatically_watch_content_you_interact_with...') }}">
<xf:checkbox>
<xf:option value="watch_email" name="option[interaction_watch_state]" checked="{{ $xf.visitor.Option.interaction_watch_state == 'watch_email' }}"
label="{{ phrase('and_receive_email_notifications') }}" />
</xf:checkbox>
</xf:option>
<xf:option name="option[content_show_signature]" checked="{$xf.visitor.Option.content_show_signature}"
label="{{ phrase('show_peoples_signatures_with_their_messages') }}" />
</xf:checkboxrow>
Thank you for your response.you need to loop the options as you have, but you're missing the xf:checkbox declaration.
as an example from the account_preferences template:
Code:<xf:checkboxrow label="{{ phrase('content_options') }}"> <xf:option value="watch_no_email" name="option[creation_watch_state]" checked="{{ $xf.visitor.Option.creation_watch_state ? true : false }}" label="{{ phrase('automatically_watch_content_you_create...') }}"> <xf:checkbox> <xf:option value="watch_email" name="option[creation_watch_state]" checked="{{ $xf.visitor.Option.creation_watch_state == 'watch_email' }}" label="{{ phrase('and_receive_email_notifications') }}" /> </xf:checkbox> </xf:option> <xf:option value="watch_no_email" name="option[interaction_watch_state]" checked="{{ $xf.visitor.Option.interaction_watch_state ? true : false }}" label="{{ phrase('automatically_watch_content_you_interact_with...') }}"> <xf:checkbox> <xf:option value="watch_email" name="option[interaction_watch_state]" checked="{{ $xf.visitor.Option.interaction_watch_state == 'watch_email' }}" label="{{ phrase('and_receive_email_notifications') }}" /> </xf:checkbox> </xf:option> <xf:option name="option[content_show_signature]" checked="{$xf.visitor.Option.content_show_signature}" label="{{ phrase('show_peoples_signatures_with_their_messages') }}" /> </xf:checkboxrow>
<xf:checkboxrow label="{$option.title}"
hint="{$hintHtml}"
explain="{$explainHtml}"
name="{$inputName}[userGroups]"
value="{{ $option.option_value.userGroups ?: [] }}">
<xf:foreach loop="$userGroups" value="$userGroup">
<xf:option label="{$userGroup.label}" value="{$userGroup.value}">
</xf:option>
</xf:foreach>
</xf:checkboxrow>
option/update action needs an options_listed in request body, and my option key is not in it, so this option was ignored. What causes that?When I have:the code still does not have the checkbox template code around the option.
<xf:checkboxrow label="{$option.title}"
hint="{$hintHtml}"
explain="{$explainHtml}"
name="{$inputName}[userGroups]"
value="{{ $option.option_value.userGroups ?: [] }}"
listclass="listColumns">
<xf:foreach loop="$userGroups" value="$userGroup">
<xf:checkbox>
<xf:option label="{$userGroup.label}" value="{$userGroup.value}" />
</xf:checkbox>
</xf:foreach>
</xf:checkboxrow>
Tag foreach contains an unexpected child element.Tag checkboxrow contains an unexpected child element. if I place the <xf:checkbox> outside <xf:foreach>)What you want to do is have this in your template:When I have:
I gotHTML:<xf:checkboxrow label="{$option.title}" hint="{$hintHtml}" explain="{$explainHtml}" name="{$inputName}[userGroups]" value="{{ $option.option_value.userGroups ?: [] }}" listclass="listColumns"> <xf:foreach loop="$userGroups" value="$userGroup"> <xf:checkbox> <xf:option label="{$userGroup.label}" value="{$userGroup.value}" /> </xf:checkbox> </xf:foreach> </xf:checkboxrow>Tag foreach contains an unexpected child element.
(GotTag checkboxrow contains an unexpected child element.if I place the<xf:checkbox>outside<xf:foreach>)
<xf:checkboxrow label="{$option.title}"
hint="{$hintHtml}"
explain="{$explainHtml}"
name="{$inputName}[userGroups]"
value="{{ $option.option_value.userGroups ?: [] }}"
listclass="listColumns">
<xf:foreach loop="$userGroups" value="$userGroup">
<xf:option label="{$userGroup.label}" value="{$userGroup.value}" />
</xf:foreach>
</xf:checkboxrow>
<xf:checkbox></xf:checkbox> wrapping around the option from your template. $viewParams = [
'option' => [
'title' => 'Allowed User Groups',
'option_value' => [
'userGroups' => [2, 4]
]
],
'hintHtml' => 'Choose which user groups can access this feature.',
'explainHtml' => 'Members of the selected groups will be granted permission.',
'inputName' => 'options[someOption]',
'userGroups' => [
['label' => 'Registered', 'value' => 2],
['label' => 'Moderators', 'value' => 3],
['label' => 'Administrators', 'value' => 4],
['label' => 'VIP Members', 'value' => 5],
['label' => 'Banned', 'value' => 6]
]
];

Thanks for your answer. I'm using these now.What you want to do is have this in your template:
Remove thatHTML:<xf:checkboxrow label="{$option.title}" hint="{$hintHtml}" explain="{$explainHtml}" name="{$inputName}[userGroups]" value="{{ $option.option_value.userGroups ?: [] }}" listclass="listColumns"> <xf:foreach loop="$userGroups" value="$userGroup"> <xf:option label="{$userGroup.label}" value="{$userGroup.value}" /> </xf:foreach> </xf:checkboxrow><xf:checkbox></xf:checkbox>wrapping around the option from your template.
I used this mock data in my controller:
PHP:$viewParams = [ 'option' => [ 'title' => 'Allowed User Groups', 'option_value' => [ 'userGroups' => [2, 4] ] ], 'hintHtml' => 'Choose which user groups can access this feature.', 'explainHtml' => 'Members of the selected groups will be granted permission.', 'inputName' => 'options[someOption]', 'userGroups' => [ ['label' => 'Registered', 'value' => 2], ['label' => 'Moderators', 'value' => 3], ['label' => 'Administrators', 'value' => 4], ['label' => 'VIP Members', 'value' => 5], ['label' => 'Banned', 'value' => 6] ] ];
and the result was:
View attachment 333931
_POST in option/update request. The hytalecn_pnl_group_after_linked option key was filtered out.
hytalecn_pnl_group_after_linked:
<xf:checkboxrow label="{$option.title}"
hint="{$hintHtml}"
explain="{$explainHtml}"
name="{$inputName}[userGroups]"
value="{{ $option.option_value.userGroups ?: [] }}"
listclass="listColumns">
<xf:foreach loop="$userGroups" value="$userGroup">
<xf:option label="{$userGroup.label}" value="{$userGroup.value}" />
</xf:foreach>
</xf:checkboxrow>
class LinkedUserGroupOption extends AbstractOption
{
public static function renderOption(Option $option, array $htmlParams)
{
$userGroupRepo = XF::repository(UserGroupRepository::class);
$groups = $userGroupRepo->getUserGroupOptionsData(false, 'option');
return static::getTemplate('admin:option_template_linked_user_group', $option, $htmlParams, [
'userGroups' => $groups,
]);
}
public static function verifyOption(array &$value, Option $option)
{
return true;
}
}
We use essential cookies to make this site work, and optional cookies to enhance your experience.