Sha*_*ell 5 zend-framework zend-form radio-button
Zend_Form_Element_Radio的默认装饰器是
<label for="type_id-1"><input type="radio" name="type_id" id="type_id-1" value="1">Pack</label>
Run Code Online (Sandbox Code Playgroud)
该label标签包装input标签.相反,我想看起来像
<input type="radio" name="type_id" id="type_id-1" value="1"><label for="type_id-1">Pack</label>
Run Code Online (Sandbox Code Playgroud)
我认为它可能与元素的"标签"有关,但这是不同的.即使使用以下代码,我仍然会收到包装广播的标签.当我使用此表单代码时.
public function init()
{
parent::init();
$this->setName('createdomain');
$type_id = new Zend_Form_Element_Radio('type_id');
$type_id->setLabel('Please Choose')
->setRequired()
->setMultiOptions(array('m' => "male", 'f' => 'female'));
$this->addElement($type_id);
$this->setElementDecorators(array(
'ViewHelper',
array('Label',array('placement' => 'APPEND')),
));
}
Run Code Online (Sandbox Code Playgroud)
结果我得到了这个HTML
<form id="createdomain" enctype="application/x-www-form-urlencoded" action="" method="post"><dl class="zend_form">
<label for="type_id-m"><input type="radio" name="type_id" id="type_id-m" value="m">male</label><br />
<label for="type_id-f"><input type="radio" name="type_id" id="type_id-f" value="f">female</label>
<label for="type_id" class="required">Please Choose</label></dl>
</form>
Run Code Online (Sandbox Code Playgroud)
请注意label标签是如何包装input标签的?
Sim*_*mon -1
这是 jQuery 的问题,而不是 Zend Framework 的问题。label 标签中元素的包装完全有效,只是 jQuery UI 不支持它。我已经发布了错误报告。
*更新答案*
不过,我认为您想要做的(正如您所评论的)是使用 jQuery UI 按钮集,这就是我遇到 jQuery UI bug 时所做的事情。简而言之,在错误修复之前您有两个选择:
1) 使用 Dennis D. 的自定义视图助手来覆盖默认的单选按钮元素。
2) 使用 Dennis D. 编写的代码修补 Zend Framework 单选按钮视图助手。它出现在文件 Zend_View_Helper_FormRadio 的第 169 行(Zend 框架版本 1.11.0)。
首先创建一个新标签并关闭标签
// Create the label
$label = '<label'
. $this->_htmlAttribs($label_attribs) . ' for="' . $optId . '">'
. (('prepend' == $labelPlacement) ? $opt_label : '')
. '<input type="' . $this->_inputType . '"'
. $opt_label
. '</label>';
Run Code Online (Sandbox Code Playgroud)
其次,将创建单选按钮的代码更改为:
// Create the radio button
$radio = '<input type="' . $this->_inputType . '"'
Run Code Online (Sandbox Code Playgroud)
第三,在视图助手中删除标签标签的结束(正如您已经完成的那样),更改:
. $endTag
. (('append' == $labelPlacement) ? $opt_label : '')
. '</label>';
Run Code Online (Sandbox Code Playgroud)
并简单地替换为:
. $endTag;
Run Code Online (Sandbox Code Playgroud)
然后使用放置定位将无线电和标签组合起来:
// Combine the label and the radio button
if ('prepend' == $labelPlacement) {
$radio = $label . $radio;
} else {
$radio = $radio . $label;
}
Run Code Online (Sandbox Code Playgroud)
就是这样(Dennis D 再次在视图助手中完成了它),但是更改后的代码应该如下所示(从第 169 行开始:
// Create the label
$label = '<label'
. $this->_htmlAttribs($label_attribs) . ' for="' . $optId . '">'
. $opt_label
. '</label>';
// Create the radio button
$radio = '<input type="' . $this->_inputType . '"'
. ' name="' . $name . '"'
. ' id="' . $optId . '"'
. ' value="' . $this->view->escape($opt_value) . '"'
. $checked
. $disabled
. $this->_htmlAttribs($attribs)
. $endTag;
// Combine the label and the radio button
if ('prepend' == $labelPlacement) {
$radio = $label . $radio;
} else {
$radio = $radio . $label;
}
// add to the array of radio buttons
$list[] = $radio;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6481 次 |
| 最近记录: |