Issues

ZF-12513: Adding subForm in displayGroup

Issue Type: New Feature Created: 2013-01-25T08:18:28.000+0000 Last Updated: 2013-04-05T16:07:01.000+0000 Status: Closed Fix version(s): Reporter: Angel K (po_taka) Assignee: None Tags: - Zend_Form

  • zend_form

Related issues: Attachments:

Description

It should be nice to be able to render subForm in DisplayGroup from main form

Comments

Posted by Frank Brückner (frosch) on 2013-01-25T08:41:03.000+0000

Hi Angel, can you give us a use case for this? Thanks.

Posted by Angel K (po_taka) on 2013-01-25T11:22:22.000+0000

There is form for "Company". Company can have a lot of phones. Every phone is sub-form. All phone forms should be in one displayGroup

Posted by Frank Brückner (frosch) on 2013-01-25T12:08:15.000+0000

Use the setElementsBelongTo method for all subforms and the HtmlTag decorator to add a fieldset element:

<pre class="highlight">
// Form
$form = new Zend_Form();
$form->setDecorators(array('FormElements', 'Form'));
$form->setElementDecorators(array('ViewHelper', 'Label'));

// Subform 1
$subForm1 = new Zend_Form_SubForm();
$subForm1->setElementsBelongTo('phones');
$subForm1->setDecorators(array('FormElements', 'Fieldset'));
$subForm1->setElementDecorators(array('ViewHelper', 'Label'));

$subForm1->addElement(
    'text',
    'foo',
    array(
        'label' => 'Foo',
    )
);

$subForm1->addDecorator('HtmlTag', array('tag' => 'fieldset', 'openOnly' => true));

// Subform 2
$form->addSubForm($subForm1, 'foo');

$subForm2 = new Zend_Form_SubForm();
$subForm2->setElementsBelongTo('phones');
$subForm2->setDecorators(array('FormElements', 'Fieldset'));
$subForm2->setElementDecorators(array('ViewHelper', 'Label'));

$subForm2->addElement(
    'text',
    'bar',
    array(
        'label' => 'Bar',
    )
);

$subForm2->addDecorator('HtmlTag', array('tag' => 'fieldset', 'closeOnly' => true));

$form->addSubForm($subForm2, 'bar');



<pre class="highlight">

    Foo
            Bar
            

Posted by Angel K (po_taka) on 2013-01-28T13:32:58.000+0000

Thank you for the example. Display groups can be emulated this way, but * u must be sure there is no later decorator that will wrap whole form * decorators can be added only once. If i want to use htmlTag twice, i need to create new class witch extends htmlTag * i need to set order to every form

<pre class="highlight">
$displayGroup = new zend_form_displaygroup()
displayGroup -> addElements(subForm1, subForm2);
$form -> addDisplayGroup(displayGroup);

is much clearer than

<pre class="highlight">
$subForm1->addDecorator('HtmlTag', array('tag' => 'fieldset', 'openOnly' => true));
$subForm2->addDecorator('HtmlTag', array('tag' => 'fieldset', 'closeOnly' => true));
$form->addSubForm($subForm1, 'foo');
$form->addSubForm($subForm2, 'bar');

Not very powerful arguments, but think about it :)

Posted by Frank Brückner (frosch) on 2013-01-28T19:51:48.000+0000

{quote}decorators can be added only once. If i want to use htmlTag twice, i need to create new class witch extends htmlTag{quote} This is wrong!

<pre class="highlight">
$subForm1->addDecorator(array('foo' => 'HtmlTag'), array('tag' => 'fieldset'));
$subForm1->addDecorator(array('bar' => 'HtmlTag'), array('tag' => 'fieldset'));

Posted by Angel K (po_taka) on 2013-01-30T07:27:56.000+0000

yep, i didn't know that, tnx :)

Posted by Ralph Schindler (ralph) on 2013-04-05T16:07:01.000+0000

This issue has been closed on Jira and moved to GitHub for issue tracking. To continue following the resolution of this issues, please visit: https://github.com/zendframework/zf1/issues/51

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts