Reputation: 177
In CakePhp 3 I have a list of parameter that i want to insert in checkbox. I have this code
<?php
echo $this->Form->input('regions', [
'options' => $regions,
'value' => Hash::extract($ad->toArray(), 'regions.{n}.id'),
'class' => 'col-xs-4',
'type' => 'select',
'multiple' => 'checkbox',
'label' => false,
'error' => [
'attributes' => ['class' => 'col-xs-12 error-message inline']
],
]);
?>
The class col-xs-4 doesn't appear. I have also inserted
'div' => 'col-xs-4'
instead of class.
how I insert a class or div at every checkbox element?
This is generated html:
<div class="input select">
<input type="hidden" name="regions" value="">
<div class="checkbox"><label for="regions-1"><input type="checkbox" name="regions[]" value="1" id="regions-1">Abruzzo</label></div>
<div class="checkbox"><label for="regions-2"><input type="checkbox" name="regions[]" value="2" id="regions-2">Basilicata</label></div>
<div class="checkbox"><label for="regions-3"><input type="checkbox" name="regions[]" value="3" id="regions-3">Calabria</label></div>
<div class="checkbox"><label for="regions-4"><input type="checkbox" name="regions[]" value="4" id="regions-4">Campania</label></div>
<div class="checkbox"><label for="regions-5"><input type="checkbox" name="regions[]" value="5" id="regions-5">Emilia Romagna</label></div>
<div class="checkbox"><label for="regions-6"><input type="checkbox" name="regions[]" value="6" id="regions-6">Friuli Venezia Giulia</label></div>
<div class="checkbox"><label for="regions-7"><input type="checkbox" name="regions[]" value="7" id="regions-7">Lazio</label></div>
<div class="checkbox"><label for="regions-8"><input type="checkbox" name="regions[]" value="8" id="regions-8">Liguria</label></div>
<div class="checkbox"><label for="regions-9"><input type="checkbox" name="regions[]" value="9" id="regions-9">Lombardia</label></div>
<div class="checkbox"><label for="regions-10"><input type="checkbox" name="regions[]" value="10" id="regions-10">Marche</label></div>
<div class="checkbox"><label for="regions-11"><input type="checkbox" name="regions[]" value="11" id="regions-11">Molise</label></div>
<div class="checkbox"><label for="regions-12"><input type="checkbox" name="regions[]" value="12" id="regions-12">Piemonte</label></div>
<div class="checkbox"><label for="regions-13"><input type="checkbox" name="regions[]" value="13" id="regions-13">Puglia</label></div>
<div class="checkbox"><label for="regions-14"><input type="checkbox" name="regions[]" value="14" id="regions-14">Sardegna</label></div>
<div class="checkbox"><label for="regions-15" class="selected"><input type="checkbox" name="regions[]" value="15" checked="checked" id="regions-15">Sicilia</label></div>
<div class="checkbox"><label for="regions-16"><input type="checkbox" name="regions[]" value="16" id="regions-16">Toscana</label></div>
<div class="checkbox"><label for="regions-17"><input type="checkbox" name="regions[]" value="17" id="regions-17">Trentino Alto Adige</label></div>
<div class="checkbox"><label for="regions-18"><input type="checkbox" name="regions[]" value="18" id="regions-18">Umbria</label></div>
<div class="checkbox"><label for="regions-19"><input type="checkbox" name="regions[]" value="19" id="regions-19">Valle d'Aosta</label></div>
<div class="checkbox"><label for="regions-20"><input type="checkbox" name="regions[]" value="20" id="regions-20">Veneto</label></div>
</div>
Upvotes: 2
Views: 4401
Reputation: 177
Finally, i Resolved with:
<?php
echo $this->Form->input('Regions',
[
'templates' => [
'checkboxWrapper' => '<div class="col-xs-4 checkbox">{{label}}</div>',
],
'options' => $regions,
'value' => Hash::extract($ad->toArray(), 'regions.{n}.id'),
'type' => 'select',
'multiple' => 'checkbox',
'label' => false,
'error' => [
'attributes' => ['class' => 'col-xs-12 error-message inline']
],
]);
?>
Documentation here: http://book.cakephp.org/3.0/en/views/helpers/form.html#customizing-the-templates-formhelper-uses
Upvotes: 6
Reputation: 11855
I would try passing the div
option.
<?php
echo $this->Form->input('regions', [
'div' => [
'class' => 'checkbox col-xs-4'
]
]);
?>
But you might need to end up changing the input field template.
Upvotes: 0