Ich versuche gerade im nl_default Template die Auflistung der zur Verfügung stehenden Verteiler von einer Checkboxliste auf eine <select> Liste umzubauen.
Alter Code:
HTML-Code:
<div class="widget widget-checkbox">
<fieldset id="ctrl_channels_<?= $this->id ?>" class="checkbox_container">
<legend class="invisible"><?= $this->channelsLabel ?></legend>
<?php foreach ($this->channels as $id => $title): ?>
<span><input type="checkbox" name="channels[]" id="opt_<?= $this->id ?>_<?= $id ?>" value="<?= $id ?>" class="checkbox"<?php if (is_array($this->selectedChannels) && in_array($id, $this->selectedChannels)): ?> checked<?php endif; ?>> <label for="opt_<?= $this->id ?>_<?= $id ?>"><?= $title ?></label></span>
<?php endforeach; ?>
</fieldset>
</div>
Output im Frontend:
HTML-Code:
<div class="widget widget-checkbox">
<fieldset id="ctrl_channels_17" class="checkbox_container">
<legend class="invisible">Verteiler</legend>
<span><input type="checkbox" name="channels[]" id="opt_17_3" value="3" class="checkbox"> <label for="opt_17_3">Bar Berlin City West</label></span>
<span><input type="checkbox" name="channels[]" id="opt_17_2" value="2" class="checkbox"> <label for="opt_17_2">Bar Allgemein</label></span>
</fieldset>
</div>
Neuer Code:
HTML-Code:
<div class="widget widget-select select">
<select id="ctrl_channels_<?= $this->id ?>" name="select-channel" class="select">
<?php foreach ($this->channels as $id => $title): ?>
<option name="channels[]" id="opt_<?= $this->id ?>_<?= $id ?>" value="<?= $id ?>"<?php if (is_array($this->selectedChannels) && in_array($id, $this->selectedChannels)): ?> selected<?php endif; ?>><?= $title ?></option>
<?php endforeach; ?>
</select>
</div>
Output im Frontend:
HTML-Code:
<div class="widget widget-select select">
<select id="ctrl_channels_17" name="select-channel" class="select">
<option name="channels[]" id="opt_17_3" value="3">Bar Berlin City West</option>
<option name="channels[]" id="opt_17_2" value="2">Bar Allgemein</option>
</select>
</div>
Ich habe sogar die eigentlich unnötigen name und id Attribute für die <option>s mitgenommen.
Leider erkennt Contao die auswahl nicht und meckert im Frontend, dass kein Verteiler gewählt wurde.
Wie bekomme ich das hin? Was fehlt Contao zur Erkennung?
Lesezeichen