-- gerardroche <[email protected]> wrote
(on Wednesday, 04 February 2009, 01:00 PM -0800):
>
> Hi, I'm wondering could somebody help with this, in reference to Zend_Form
> and decorators.
>
> Basically I'm trying to add a css class to a fieldset element.
>
> My forms are created like Pádraic Bradys in his blog application tutorial,
> http://blog.astrumfutura.com/archives/360-Example-Zend-Framework-Blog-Application-Tutorial-Part-6-Introduction-to-Zend_Form-and-Authentication-with-Zend_Auth.html
>
>
> with the decorator:
>
> protected $_standardGroupDecorator = array(
> 'FormElements',
> array('HtmlTag', array('tag' => 'ul')),
> 'Fieldset'
> );
>
> How do i add a class "elements-group" to the fieldset without losing the
> unordered list within the fieldset?
>
> I've tried all sorts, if i do:
>
> protected $_buttonGroupDecorator = array(
> 'FormElements',
> array('HtmlTag', array('tag' => 'ul')),
> 'Fieldset' => array('HtmlTag', array('tag'=>'fieldset', 'class' =>
> 'elements-group'))
> );
Try changing the above to this:
protected $_buttonGroupDecorator = array(
'FormElements',
array('HtmlTag', array('tag' => 'ul')),
array('Fieldset', array('class' => 'elements-group')),
);
There is a fieldset decorator already, and you can pass it options, just
as you can the other decorators.
> the fieldset will have the class "elements-goup" but the unordered list
> disappears, i need to the ul within the fieldset.
>
>
> There's longer description below, any help would be appreciated.
>
>
>
>
>
> ---------------
> ---------------
> ---------------
> ---------------
>
>
>
> I have all my decorators in properties and then add them to the elements on
> the fly to produce element lists within fieldsets, here are the properties:
>
>
> protected $_standardElementDecorator = array(
> 'Errors',
> 'ViewHelper',
> 'Description',
> array('Label'),
> array('HtmlTag', array('tag'=>'li', 'class' => 'form-row'))
> );
>
> protected $_standardElementFileDecorator = array(
> 'Errors',
> 'File',
> 'Description',
> array('Label'),
> array('HtmlTag', array('tag'=>'li'))
> );
>
> protected $_buttonElementDecorator = array(
> 'ViewHelper'
> );
>
> protected $_standardGroupDecorator = array(
> 'FormElements',
> array('HtmlTag', array('tag' => 'ul')),
> 'Fieldset'
> );
>
> protected $_buttonGroupDecorator = array(
> 'FormElements',
> 'Fieldset' => array('HtmlTag', array('tag'=>'fieldset', 'class' =>
> 'submit-row'))
> );
>
> protected $_noElementDecorator = array(
> 'ViewHelper'
> );
>
>
> and in the constructor:
>
>
>
> public function __construct($options = null)
> {
> parent::__construct(array('disableLoadDefaultDecorators' => true));
>
> $this->setMethod('post');
> $this->setAttrib('accept-charset', 'UTF-8');
> $this->setDecorators(array(
> 'Description',
> 'Errors',
> 'FormElements',
> 'Form'
> ));
> }
>
>
>
> so creating a form:
>
>
>
>
> $this->setName('formId');
> $this->addElement('text', 'name', array(
> 'decorators' => $this->_standardElementDecorator,
> 'label' => 'Name',
> 'required' => true
> ));
> $this->addDisplayGroup(array('name'), 'elementGroup',
> array(
> 'decorators' => $this->_standardGroupDecorator
> ));
> $this->addElement('submit', 'submit',
> array(
> 'decorators' => $this->_buttonElementDecorator,
> 'label' => 'Save',
> 'ignore' => true
> ));
> $this->addDisplayGroup(array('submit'), 'submitGroup',
> array(
> 'decorators' => $this->_buttonGroupDecorator
> ));
>
>
> will produce the following markup :
>
> <form id="formId" method="post" accept-charset="UTF-8" action="/to/action">
> <fieldset id="fieldset-elementGroup">
> <ul>
> <li class="form-row">
> <label for="name" class="required">Name</label>
> <input type="text" name="name" id="name" value="" />
> </li>
> </ul>
> </fieldset>
> <fieldset class="submit-row">
> <input type="submit" name="submit" id="submit" value="Save" />
> </fieldset>
> </form>
>
>
> I want to add a class to the fieldset display group. The submit row has a
> class "submit-row" which is done by using the decorator:
>
> protected $_buttonGroupDecorator = array(
> 'FormElements',
> 'Fieldset' => array('HtmlTag', array('tag'=>'fieldset', 'class' =>
> 'submit-row'))
> );
>
>
> but my elements need to be wrapped in an unordered list. So is use the
> display groupd decorator:
>
>
> protected $_standardGroupDecorator = array(
> 'FormElements',
> array('HtmlTag', array('tag' => 'ul')),
> 'Fieldset'
> );
>
>
> So, how do i add a class to the fieldset?
>
> I've tried all sorts, if i do the following, which i though should work, i
> lose the unordered list:
>
> protected $_buttonGroupDecorator = array(
> 'FormElements',
> array('HtmlTag', array('tag' => 'ul')),
> 'Fieldset' => array('HtmlTag', array('tag'=>'fieldset', 'class' =>
> 'elements-row'))
> );
>
>
> <form id="formId"method="post" accept-charset="UTF-8" action="/to/action">
> <fieldset class="elements-row">
> <li class="form-row">
> <label for="name" class="required">Name</label>
> <input type="text" name="name" id="name" value="" />
> </li>
> </fieldset>
> <fieldset class="submit-row">
> <input type="submit" name="submit" id="submit" value="Save" />
> </fieldset>
> </form>
>
>
>
> I'm sorry about the long post littered with snippits, any help would be
> appreciated.
>
>
>
>
>
> --
> View this message in context:
> http://www.nabble.com/Zend_Form---decorators%3A-adding-a-css-class-to-a-fieldset---tp21839519p21839519.html
> Sent from the Zend Framework mailing list archive at Nabble.com.
>
--
Matthew Weier O'Phinney
Software Architect | [email protected]
Zend Framework | http://framework.zend.com/