[英]How to enable displaying the global label unsing FormMultiCheckbox in ZF2?
I'm using Zend\\Form\\Element\\MultiCheckbox
with Zend\\Form\\View\\Helper\\FormMultiCheckbox
: 我正在使用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);
It works, but the " global label
" is not displayed. 它可以工作,但是不会显示“ global label
”。 It gets displayed, when I'm using Zend\\Form\\View\\Helper\\FormElement
, but the FormMultiCheckbox
seems to ignore the "global label
". 当我使用Zend\\Form\\View\\Helper\\FormElement
,它会显示Zend\\Form\\View\\Helper\\FormElement
,但是FormMultiCheckbox
似乎忽略了“全局label
”。
How to make FormMultiCheckbox
display the label
of the checkbox list? 如何使FormMultiCheckbox
显示复选框列表的label
?
Have you tried with formRow()
. 您是否尝试过formRow()
。 For me it works. 对我来说,它有效。 This does not appear to be managed in formMultiCheckbox()
. 在formMultiCheckbox()
似乎没有对此进行管理。 See lines 182-193
, file zend-form/src/View/Helper/FormRow.php
. 参见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.