admin管理员组文章数量:1024582
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:
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:
本文标签: htmlYii2 ActiveForm CheckboxList Group SeperatorStack Overflow
版权声明:本文标题:html - Yii2 ActiveForm CheckboxList Group Seperator - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745591094a2157890.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论