Hello there,
A customer of mine requires me to create some kind of "locked" for fields.
Not entering in the details for this stuff, but I need to store somewhere:
a) the Zend_Form_Element value
b) the Zend_Form_Element_Checkbox value (a checkbox that defines the field
as "locked")

Here's the big trouble: this customer is completely focused on graphic
details (omg!) and absolutely wants display groups.

Here's a preview of what I currently have and that has to be reworked in a
Zend_Form based implementation:

http://marco-pivetta.com/screenshots/Zend_Form_DisplayGroup_and_parallel_fields.png
(the switches on the right are checkboxes hidden by css sprites)


In a normal case I would have built some form like this one:

//Pseudocode
$form = new MyForm(array(
  'field1' => new LockedFieldForm((
    new Zend_Form_Element_Text('field', /*...*/),
    new Zend_Form_Element_Checkbox('lock', /*...*/)
  )),
  'field2' => new LockedFieldForm((
    new Zend_Form_Element_Textarea('field', /*...*/),
    new Zend_Form_Element_Checkbox('lock', /*...*/)
  )),
  'field3' => new LockedFieldForm((
    new Zend_Form_Element_Select('field', /*...*/),
    new Zend_Form_Element_Checkbox('lock', /*...*/)
  )),
  'field1' => new LockedFieldForm((
    new Zend_Form_Element_OtherStuff('field', /*...*/),
    new Zend_Form_Element_Checkbox('lock', /*...*/)
  )),
));

This allows me to play around with decorators within a "row" of my form and
encapsulate my field persistence logic within a LockedFieldForm, by hiding
the entire "lock" stuff. I can also play around with decorators to let
subforms look exactly like other form elements...

The pitfall is that Zend_Form_DisplayGroup allows me to group only elements
of the same form (as far as I know), and would also make it hard to couple
fields with their locks. As you can see in the screenshot linked before, I
need to separate some fields keeping them in the same form. This is what
DisplayGroup(s) are for.

What I was trying to achieve is something like:
$displayGroup->addElement($form->getSubForm('field1')); //Obviously doesn't
work...

Any ideas/suggestions?
Shall I tell my customer that I can't use display groups?
Is there some other method to encapsulate the lock logic? Anything different
from Zend_Form_SubForm? Extending Zend_Form_Element seems to be quite
complicated...

Thank you in advance for any hints :)

Marco Pivetta
@Ocramius <http://twitter.com/Ocramius>
http://marco-pivetta.com

Reply via email to