- Set the input name as an array
authorCyperghost <olaf_schmitz_1@t-online.de>
Fri, 2 Aug 2024 13:45:47 +0000 (15:45 +0200)
committerCyperghost <olaf_schmitz_1@t-online.de>
Fri, 2 Aug 2024 13:45:47 +0000 (15:45 +0200)
- Check whether the value is in the value-array and then set the `selected`.

com.woltlab.wcf/templates/shared_multipleSelectFormField.tpl

index b83137eb1a88d9ab83884afa525d89989f8ff3c7..7f5fdd38290700dd305a5bd7e56b08545089a049 100644 (file)
@@ -1,15 +1,14 @@
 <select
        id="{$field->getPrefixedId()}"
-       name="{$field->getPrefixedId()}"
+       name="{$field->getPrefixedId()}[]"
        {if !$field->getFieldClasses()|empty} class="{implode from=$field->getFieldClasses() item='class' glue=' '}{$class}{/implode}"{/if}
        {if $field->isRequired()} required{/if}
        multiple
 >
-       <option value="">{lang}wcf.global.noSelection{/lang}</option>
        {foreach from=$field->getNestedOptions() item=__fieldNestedOption}
                <option
                        value="{$__fieldNestedOption[value]}"
-                       {if $field->getValue() == $__fieldNestedOption[value] && $__fieldNestedOption[isSelectable]} selected{/if}
+                       {if $field->getValue() !== null && $__fieldNestedOption[value]|in_array:$field->getValue() && $__fieldNestedOption[isSelectable]} selected{/if}
                        {if $field->isImmutable() || !$__fieldNestedOption[isSelectable]} disabled{/if}
                >{@'&nbsp;'|str_repeat:$__fieldNestedOption[depth] * 4}{@$__fieldNestedOption[label]}</option>
        {/foreach}