Zend: ViewScript decorator and array notation
Asked Answered
P

1

2

I have a matrix of checkboxes which I am laying out in a table. I need to pull this matrix into a number of forms, and sometimes multiple times on one form, so I have set it up as a subform.

After much research and deliberation, I decided the best way to decorate the subform was using the viewScript decorator. The code for adding the subform to the form looks something like this:

$this->addSubForm(new Test_Form_Connection_Config_Base(), 'user');
$this->user->setDecorators(array(
    array('viewScript', array('viewScript' => '_forms/userConfig.phtml')),
          'Description',
          'FieldSet',
        ));

For the most part this works fine however the one problem I have is that I can't get array notation to work. Obviously this becomes a problem when I include the matrix more than once on a particular form.

I tried using setIsArray(true) however this had no effefct. It seems that I need to run the FormElements decorator to get the array notation, but this then gives me a duplicate set of fields on the page (rendered once by FormElements, and once by viewScript).

I could manually construct the name of each element to reflect array notation, but this seems like the long way around. Are there any other options that I'm missing?

Thanks...!

Pitterpatter answered 23/8, 2011 at 0:19 Comment(0)
F
2

Before using the ViewScript decorator, you should always use the PrepareElements decorator to normalize names.

See http://framework.zend.com/manual/en/zend.form.standardDecorators.html#zend.form.standardDecorators.prepareElements

Fimble answered 23/8, 2011 at 0:28 Comment(1)
Phil, is there no end to your genius?Pitterpatter

© 2022 - 2024 — McMap. All rights reserved.