【发布时间】:2017-03-14 14:25:35
【问题描述】:
在我的表单中,我有一个单选按钮集 foo,定义如下:
$this->add(
[
'type' => 'radio',
'name' => 'foo',
'options' => [
'label' => 'foo',
'value_options' => [
[
'value' => Foo::BAR,
'label' => 'bar'
],
[
'value' => Foo::BUZ,
'label' => 'buz'
]
],
'label_attributes' => [
'class' => 'col-md-12',
]
],
'attributes' => [
'class' => 'field-foo'
]
]);
在视图脚本中它是这样调用的:
$this->formRow($myFieldset->get('foo'));
所以我得到了这个 HTML:
<fieldset>
<legend>foo</legend>
<label class="col-md-12">
<input type="radio" value="bar" class="field-foo" name="my_fieldset[foo]">bar
</label>
<label class="col-md-12">
<input type="radio" value="buz" class="field-foo" name="my_fieldset[foo]">buz
</label>
</fieldset>
现在我想将此单选按钮集标记为必需。对于input[type="text"] 字段,我通过label 进行管理:
label.required:before {
content: '* ';
color: #ff0000;
}
在这种情况下,我需要访问legend 或至少fieldset,以便定义
fieldset > legend.required:before, /*or*/
fieldset.required > legend:before {
content: '* ';
color: #ff0000;
}
如何做到这一点?如何为 Zend Framework 2 中设置的单选按钮的fieldset / legend 元素设置一个类?
【问题讨论】:
标签: php forms zend-framework2 zend-form zend-form-element