【问题标题】:Zend Framework: Adding Radio buttons to a fieldsetZend 框架:向字段集添加单选按钮
【发布时间】:2014-03-18 10:02:34
【问题描述】:

Moin Moin,你好,

我是 Zend 框架的新手,所以我希望我的问题对你来说不是什么大问题。

我正在使用 Zend Framework 1.12.5 和 jQuery Mobile 1.4.0。
我想做的是在我的注册表单中添加两个水平单选按钮。在阅读了 jQuery 文档后,我发现您需要将单选按钮添加到属性为“data-type="horizo​​ntal"”的字段集中。但我不知道如何在框架中做到这一点。

至少我想要这样的东西:

<fieldset data-role="controlgroup" data-type="horizontal">
        <legend>Gender</legend>
        <input name="radio-choice-h-2" id="radio-choice-h-2a" value="on" checked="checked" type="radio">
        <label for="radio-choice-h-2a">male</label>
        <input name="radio-choice-h-2" id="radio-choice-h-2b" value="off" type="radio">
        <label for="radio-choice-h-2b">female</label>
</fieldset>

这是我的 Zend-form 的代码:

   $this->addElement('radio', 'gender', array(
        'label'=>'Gender',
        'value'    => '0',
        'multiOptions'=>array(
            '0' => 'male',
            '1' => 'female',
        ),
        'separator' => ' ',
        'decorators' => array(
            'ViewHelper',
        )
    ));

我尝试为字段集创建一个自己的表单元素并在其中包含单选按钮,但字段集是同时创建和关闭的。 (如果你愿意,我也可以发布源代码。) 所以我的 HTML 看起来像这样:

<form id="register" enctype="application/x-www-form-urlencoded" method="post" autocomplete="off" action=""><div class="form">
<fieldset data-role="controlgroup" data-type="horizontal"></fieldset>
<dt id="gender-label"><label class="optional">Gender</label></dt>

<label><input type="radio" name="gender" ...

如您所见:它不起作用。

有没有人也遇到过这个问题,可以给我推动正确的方向?

感谢您的帮助。
巴兹提

【问题讨论】:

    标签: jquery-mobile zend-framework radio-button zend-form fieldset


    【解决方案1】:

    不幸的是 prepend/append 装饰器没有解决我的问题(或者我对 zend 的经验太少,无法以功能方式创建它)但我找到了另一个解决方案:

    $this->addElement('radio', 'gender', array(
        'label'=>'Gender',
        'value'    => '0',
        'multiOptions'=>array(
            '0' => 'female',
            '1' => 'male',
        ),
        'separator' => ' ',
        'decorators' => array(
            'ViewHelper', array(
                array('fieldset' => 'HtmlTag'),
                array('tag' => 'fieldset',
                      'data-role' => 'controlgroup',
                      'data-type' => 'horizontal')
            )
        )
    ));
    

    感谢您的帮助,它为我提供了解决此问题的正确方向。 =)

    【讨论】:

      【解决方案2】:

      就个人而言,我会添加一个 prepend 和一个 append 自定义装饰器。

      这里是website (wiip.fr),它让我知道了这种技术(法语但例子很清楚),否则,我找到了it。当然还有其他的:)

      我希望这个对你有用。 :)

      【讨论】:

        猜你喜欢
        • 2010-11-07
        • 1970-01-01
        • 2012-08-26
        • 2011-10-05
        • 2018-12-06
        • 2011-07-19
        • 1970-01-01
        • 2014-01-03
        • 2016-06-12
        相关资源
        最近更新 更多