【问题标题】:Add multiple element groups into one display group using Zend_Form使用 Zend_Form 将多个元素组添加到一个显示组中
【发布时间】:2011-09-27 06:29:20
【问题描述】:

我正在使用 Zend_Form 输出我的表单,我正在尝试对 's 中的按钮元素进行分组,然后将它们添加到字段集。

我做到的最好的是:

<fieldset id="fieldset-group1">
    <div class="buttons">
        <button name="submit_form" id="submit_form" type="submit">Submit</button>
        <button name="cancel_form" id="cancel_form" type="submit">Cancel</button>
    </div>
</fieldset>
<fieldset id="fieldset-group2">
    <div class="buttons">
        <button name="reset_form" id="reset_form" type="submit">Reset</button>
        <button name="button_form" id="button_form" type="button">Button</button>
    </div>
</fieldset>

其中两个元素组位于两个单独的显示组中。我通过将 DisplayGroup HtmlTag Decorator 'tag' 选项设置为 'div.

我想要实现的是:

<fieldset id="fieldset-group1">
    <div class="buttons">
        <button name="submit_form" id="submit_form" type="submit">Submit</button>
        <button name="cancel_form" id="cancel_form" type="submit">Cancel</button>
    </div>

    <div class="buttons">
        <button name="reset_form" id="reset_form" type="submit">Reset</button>
        <button name="button_form" id="button_form" type="button">Button</button>
    </div>
</fieldset>

两个 div 位于一个显示组中。

我希望我可以使用 HtmlTag 装饰器可用的 'openOnly' 和 'closeOnly' 选项,但它们不适用于 DisplayGroups。

除了扩展 Zend_View_Helper_Fieldset 来做我想做的事情之外,还有更好的方法吗?

【问题讨论】:

    标签: php zend-framework zend-form zend-decorators


    【解决方案1】:
    'decorators'=>array('FormElements',
                         array(array('divtag'=>'HtmlTag'),'options'=>array('tag'=>'div')),
                         array(array('fstag'=>'HtmlTag'),'options'=>array('tag'=>'fieldset','openOnly'=>true)),
                       )
    

    openOnly/closeOnly 也可以与 DisplayGroups 一起使用

    【讨论】:

    • 嘿,这确实回答了我提出的问题!但是,将 fieldset 装饰器更改为 htmlTag 装饰器会让我失去向 fieldset 添加图例的能力,因为它不会使用 fieldset 视图帮助器。
    • 是的......一种解决方案是使用描述来表现得像传说array('Description','options' =&gt; array('tag'=&gt;'legend'))
    • 您也可以尝试将这些组放在一个子表单上并在子表单上应用一个字段集。
    【解决方案2】:

    他们总是说你可以编写自己的装饰器。您要做的不是扩展 view_helper 而是编写自己的装饰器。这里的装饰器不是fieldset afaik,而是fieldset里面使用的FormElements。它是 FormElements 装饰器,它不是为处理您正在寻找的 div 而设计的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-29
      • 1970-01-01
      • 2012-06-22
      相关资源
      最近更新 更多