I am working with zf2 and the TwbBundle. I wanto to add two buttons as a button group to the end of various forms. When I directly add them to the Form as two objects with the button-group option set, then it is rendered fine.
$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 results in:
<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>
But once I extract them into a reusable fieldset each of the elements gets wrapped in its own form-group element and no longer renders as a button 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>
I tried adding css classes or button-group options to the fieldset in the form class, but nothing had the desired effect.
Anyone had the same problem or might have an idea on how to realize this?
Cheers Jens
Edit: On request additional code. How the fieldset is defined:
<?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',
),
));
}
}
And included with this:
$this->add(array(
'name' => 'form-controls',
'type' => 'Application\Form\FormControls',
));