I am trying to place a line in between a list of values in a Yii2 CheckboxList. For now I am just trying to get it to work using the yii Bootstrap 5 Html form field.
When using this:
<?= Html::checkboxList('field_name','',[
'anisation_name'=>'Organisation Name',
'anisation_vat_number'=>'Organisation VAT Number',
'invoice_number'=>'Invoice Number',
'invoice_date'=>'InvoiceDate,],
$options=['separator' => '<hr>', 'class'=>'form-control']) ?>
I get this:
Organisation Name
---------------------------
Organisation VAT Number
---------------------------
Invoice Number
---------------------------
Invoice Date
---------------------------
What I want is this:
Organisation Name
Organisation VAT Number
---------------------------
Invoice Number
Invoice Date
---------------------------
Is this possible with HTML Bootstrap and how to implement with Yii2 ?
I am trying to place a line in between a list of values in a Yii2 CheckboxList. For now I am just trying to get it to work using the yii Bootstrap 5 Html form field.
When using this:
<?= Html::checkboxList('field_name','',[
'anisation_name'=>'Organisation Name',
'anisation_vat_number'=>'Organisation VAT Number',
'invoice_number'=>'Invoice Number',
'invoice_date'=>'InvoiceDate,],
$options=['separator' => '<hr>', 'class'=>'form-control']) ?>
I get this:
Organisation Name
---------------------------
Organisation VAT Number
---------------------------
Invoice Number
---------------------------
Invoice Date
---------------------------
What I want is this:
Organisation Name
Organisation VAT Number
---------------------------
Invoice Number
Invoice Date
---------------------------
Is this possible with HTML Bootstrap and how to implement with Yii2 ?
Share Improve this question asked Nov 18, 2024 at 22:12 QuentinbQuentinb 5101 gold badge9 silver badges33 bronze badges 1- I have no idea why stackoverflow is changing the color on some of the lines. The color has nothing to do with what I need, just the format/layout :-) – Quentinb Commented Nov 18, 2024 at 22:14
1 Answer
Reset to default 1What I am thinking is to create a custom item rendered using the $index
.
Edited:
Another workaround is to use the $key as a flag
for your "separator".
<?= Html::checkboxList('field_name', '', [
'anisation_name' => 'Organisation Name',
'anisation_vat_number' => 'Organisation VAT Number',
'separator' => '',
'invoice_number' => 'Invoice Number',
'invoice_date' => 'Invoice Date',
'another_menu' => 'Another Menu',
'another_menu' => 'Another Menu',
'another_menu' => 'Another Menu',
'separator' => '',
], [
'item' => function ($index, $label, $name, $checked, $value) {
if ($value === 'separator') {
return '<hr>';
}
return "<label class='form-control'>" . Html::checkbox($name, $checked, ['value' => $value]) . " $label</label>";
}
]) ?>
Our homework is to put the 'separator' key anywhere inside the array of $items.
Result: