簡體   English   中英

如何在ZF2中啟用在不使用FormMultiCheckbox的情況下顯示全局標簽的功能?

[英]How to enable displaying the global label unsing FormMultiCheckbox in ZF2?

我正在使用Zend\\Form\\Element\\MultiCheckbox Zend\\Form\\View\\Helper\\FormMultiCheckbox Zend\\Form\\Element\\MultiCheckbox

MyFieldset.php

// namespace ...;
// use ....;
class MyFieldset extends Fieldset
{
    // ...
    public function init()
    {
        parent::init();
        $this->add(
            [
                'type' => 'multi_checkbox',
                'name' => 'mymulticheckbox',
                'options' => [
                    'label' => _('global label'),
                    'label_attributes' => [
                        'class' => 'col-md-3',
                    ],
                    'value_options' => [
                        [
                            'value' => 'foo',
                            'label' => 'FOO',
                        ],
                        [
                            'value' => 'bar',
                            'label' => 'BAR',
                        ],
                        [
                            'value' => 'buz',
                            'label' => 'BUZ',
                        ],
                    ]
                ],
            ]
        );
    }
    // ...
}

myform.phml

use Zend\Form\View\Helper\FormMultiCheckbox;
echo $this->formMultiCheckbox($myFieldset->get('mymulticheckbox'), FormMultiCheckbox::LABEL_PREPEND);

它可以工作,但是不會顯示“ global label ”。 當我使用Zend\\Form\\View\\Helper\\FormElement ,它會顯示Zend\\Form\\View\\Helper\\FormElement ,但是FormMultiCheckbox似乎忽略了“全局label ”。

如何使FormMultiCheckbox顯示復選框列表的label

您是否嘗試過formRow() 對我來說,它有效。 formMultiCheckbox()似乎沒有對此進行管理。 參見182-193行,文件zend-form/src/View/Helper/FormRow.php

// Multicheckbox elements have to be handled differently as the HTML standard does not allow nested
// labels. The semantic way is to group them inside a fieldset
if ($type === 'multi_checkbox'
    || $type === 'radio'
    || $element instanceof MonthSelect
    || $element instanceof Captcha
) {
    $markup = sprintf(
        '<fieldset><legend>%s</legend>%s</fieldset>',
        $label,
        $elementString
    );

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM