MOON
Server: Apache
System: Linux res.emeff.ca 3.10.0-962.3.2.lve1.5.24.10.el7.x86_64 #1 SMP Wed Mar 20 07:36:02 EDT 2019 x86_64
User: accemeff (1004)
PHP: 7.0.33
Disabled: NONE
Upload Files
File: /home/accemeff/vendor/craftcms/cms/docs/ja/multi-select-fields.md
# マルチセレクトボックスフィールド

マルチセレクトボックスフィールドは、複数選択形式の入力を提供します。

## 設定

マルチセレクトボックスフィールドの設定は、次の通りです。

* **マルチセレクトボックスのオプション** – フィールドで利用可能なオプションを定義します。オプションの値とラベルを別々に設定したり、デフォルトで選択状態にしておくものを選択できます。

## テンプレートの実例

#### 選択されたオプションをループ

```twig
{% for option in entry.multiselectFieldHandle %}
    Label: {{ option.label }}
    Value: {{ option }} or {{ option.value }}
{% endfor %}
```

#### 利用可能なすべてのオブションをループ

```twig
{% for option in entry.multiselectFieldHandle.options %}
    Label:    {{ option.label }}
    Value:    {{ option }} or {{ option.value }}
    Selected: {{ option.selected ? 'Yes' : 'No' }}
{% endfor %}
```

#### いずれかのオプションが選択されているかを確認

```twig
{% if entry.multiselectFieldHandle|length %}
```

#### 特定のオプションが選択されているかを確認

```twig
{% if entry.multiselectFieldHandle.contains('optionValue') %}
```

#### 投稿フォーム

```twig
{% set field = craft.app.fields.getFieldByHandle('multiselectFieldHandle') %}

{# Include a hidden input first so Craft knows to update the
   existing value, if no options are selected. #}
<input type="hidden" name="fields[multiselectFieldHandle]" value="">

<select multiple name="fields[multiselectFieldHandle][]">
    {% for option in field.options %}

        {% set selected = entry is defined
            ? entry.multiselectFieldHandle.contains(option.value)
            : option.default %}

        <option value="{{ option.value }}"
                {% if selected %}selected{% endif %}>
            {{ option.label }}
        </option>
    {% endfor %}
</select>
```