最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

html - Yii2 ActiveForm CheckboxList Group Seperator - Stack Overflow

matteradmin6PV0评论

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
Add a comment  | 

1 Answer 1

Reset to default 1

What 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:

Post a comment

comment list (0)

  1. No comments so far