[英]zf2 TwbBundle button group inside fieldset
我正在使用zf2和TwbBundle。 我想將兩個按鈕作為按鈕組添加到各種表單的末尾。 當我將它們直接設置為兩個帶有按鈕組選項的對象添加到窗體中時,它將呈現為很好。
$this->add(array(
'name' => 'submit',
'type' => 'Button',
'options' => array(
'label' => 'Speichern',
'button-group' => 'group-1',
),
'attributes' => array(
'type' => 'submit',
'class' => 'btn btn-primary btn-lg',
),
));
$this->add(array(
'name' => 'cancel',
'type' => 'Button',
'options' => array(
'label' => 'Abbrechen',
'button-group' => 'group-1',
),
'attributes' => array(
'type' => 'submit',
'class' => 'btn btn-default btn-lg',
),
));
結果是:
<div class="form-group ">
<div class="btn-group">
<button type="submit" name="submit" class="btn btn-primary btn-lg" value="">Speichern</button>
<button type="submit" name="cancel" class="btn btn-default btn-lg" value="">Abbrechen</button>
</div>
</div>
但是,一旦將它們提取到可重用的字段集中,每個元素都將包裝在其自己的form-group元素中,並且不再呈現為按鈕組。
<fieldset>
<div class="form-group ">
<button type="submit" name="form-controls[submit]" class="btn btn-primary btn-lg" value="">Speichern</button>
</div>
<div class="form-group ">
<button type="submit" name="form-controls[cancel]" class="btn btn-default btn-lg" value="">Abbrechen</button>
</div>
</fieldset>
我嘗試將CSS類或按鈕組選項添加到表單類的字段集中,但沒有任何效果。
任何人都有同樣的問題,或者對如何實現這個想法有想法?
干杯詹斯
編輯:根據要求提供其他代碼。 如何定義字段集:
<?php
namespace Application\Form;
use Zend\Form\Fieldset;
class FormControls extends Fieldset
{
public function __construct()
{
parent::__construct('form-controls');
$this->add(array(
'name' => 'submit',
'type' => 'Button',
'options' => array(
'label' => 'Speichern',
'button-group' => 'group-1',
),
'attributes' => array(
'type' => 'submit',
'class' => 'btn btn-primary btn-lg',
),
));
$this->add(array(
'name' => 'cancel',
'type' => 'Button',
'options' => array(
'label' => 'Abbrechen',
'button-group' => 'group-1',
),
'attributes' => array(
'type' => 'submit',
'class' => 'btn btn-default btn-lg',
),
));
}
}
並包含以下內容:
$this->add(array(
'name' => 'form-controls',
'type' => 'Application\Form\FormControls',
));
之所以會獲得額外的fieldset標簽,是因為您是通過fieldset添加元素的。
FormControls類擴展Fieldset
$this->add(array(
'name' => 'form-controls',
'type' => 'Application\Form\FormControls',
));
解決方案是具有(form / fieldset)類,該類添加:
$this->add(array(
'name' => 'form-controls',
'type' => 'Application\Form\FormControls',
));
擴展包含以下內容的(表單/字段集)類:
$this->add(array(
'name' => 'submit',
'type' => 'Button',
'options' => array(
'label' => 'Speichern',
'button-group' => 'group-1',
),
'attributes' => array(
'type' => 'submit',
'class' => 'btn btn-primary btn-lg',
),
));
$this->add(array(
'name' => 'cancel',
'type' => 'Button',
'options' => array(
'label' => 'Abbrechen',
'button-group' => 'group-1',
),
'attributes' => array(
'type' => 'submit',
'class' => 'btn btn-default btn-lg',
),
));
因此,您可以使用可重復使用的按鈕。 結果將是如下結構: CoolForm擴展ButtonForm擴展Form ,其中:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.