Matthew Weier O'Phinney-3 wrote:
>
> And now we get to the meat of the problem:
>
>> I have to set decorators and element filters for every subform
>> separately.
>
> I still content that Display Groups are the incorrect place to do this;
> what you are doing is, quite simply, logical grouping (an action by the
> user determines what group of elements to show). That said, it's
> obvious that there's some capabilities you need that Zend_Form does not
> currently support: the ability for setElement*() to affect *sub forms*.
>
> This would allow you to call setElementPrefixPath, setElementFilters,
> and setElementDecorators *once*, on the parent form, and have it
> propagate to all elements in all sub forms. I think this is a reasonable
> request to make.
>
> So, if you'd be so kind, could you place an issue in the tracker for
> this?
>
> In the meantime, I'd suggest creating your own Zend_Form subclass that
> overrides these methods to not only iterate over elements, but also sub
> forms (let me know if you need help with this). The workflow at form
> creation would then be:
>
> * create elements
> * create sub forms and their elements
> * call the appropriate setElement*() methods
>
> --
> Matthew Weier O'Phinney
> Software Architect | [EMAIL PROTECTED]
> Zend - The PHP Company | http://www.zend.com/
>
>
I would like to place an issue to tracker, but I still don't have write
access even if I wrote an email to [EMAIL PROTECTED] at least a month ago. I try
it again.
Concerning subclassing Zend_Form, I did it yesterday. I have modified
constructor, addSubForm and render methods in following way. Is it correct
considering philosophy of Zend_Form? I set decorators to subforms at render
method to ensure that al elements are set properly, because decorators
affect only existing elements in forms.
class Jp_Form extends Zend_Form
{
/**
* Constructor
*
* @param mixed $options
* @return void
*/
public function __construct($options = null)
{
...
// don't load default decorators, everything is done by custom ones
$options['disableLoadDefaultDecorators'] = true;
parent::__construct($options);
$this->addElementPrefixPath('Jp_Form_Decorator',
'Jp/Form/Decorator', Zend_Form::DECORATOR);
$this->addDisplayGroupPrefixPath('Jp_Form_Decorator',
'Jp/Form/Decorator', Zend_Form::DECORATOR);
$this->addPrefixPath('Jp_Form_Decorator', 'Jp/Form/Decorator',
Zend_Form::DECORATOR);
$this->addDecorators(array('FormElements', 'Form'));
}
public function addSubForm(Zend_Form $form, $name, $order = null)
{
$form->addElementPrefixPath('Jp_Form_Decorator',
'Jp/Form/Decorator', Zend_Form::DECORATOR);
$form->addDisplayGroupPrefixPath('Jp_Form_Decorator',
'Jp/Form/Decorator', Zend_Form::DECORATOR);
$form->addPrefixPath('Jp_Form_Decorator', 'Jp/Form/Decorator',
Zend_Form::DECORATOR);
$form->addDecorators(array('FormElements'));
parent::addSubForm($form, $name, $order);
}
public function render(Zend_View_Interface $view = null)
{
$this->setSubFormDecorators(array('FormElements', 'SubForm'));
// walk subforms recursively using stack and set decorators to them
$stack = array($this);
while (!empty($stack)) {
$form = array_pop($stack);
$form->setElementDecorators(array('Element'));
$form->setDisplayGroupDecorators(array('FormElements',
'DisplayGroup'));
foreach ($form->getSubForms() as $subForm) {
$stack[] = $subForm;
}
}
return parent::render($view);
}
}
--
View this message in context:
http://www.nabble.com/Zend_Form-feature-request---nested-display-groups-tp16572736p16596270.html
Sent from the Zend Framework mailing list archive at Nabble.com.