开发者

Zend Form Decorator - adding options to tag of an input Label

开发者 https://www.devze.com 2023-02-17 20:04 出处:网络
I\'m trying to achieve the following html output using Zend_Form Decorator: <tr> <td id=\"from-label\" **class=\"labelcell\"**><label for=\"from\" class=\"required\">From</label&

I'm trying to achieve the following html output using Zend_Form Decorator:

<tr>
  <td id="from-label" **class="labelcell"**><label for="from" class="required">From</label></td> 
  <td><input type="text" name="from" id="from" value="" class="text"></td>
</tr> 

I'm trying to add class attribute and for example inline style attribute on the enclosing tag of the Label. In the above example I want to add class="labelcell"

The decorator statements are as follows:

    $from = $this->createElement('text', 'from', array(
                            'validators'=> array(array('regex', false, '/^[0-9]+/i')),
                            'required'=> true,
                            'label'=> 'From'
                        )
                    );
        $from->setAttrib('class', 'text');
        $from->setDecorators(
                array(
                'ViewHelper',
                'Description',
                'Errors',
                array(array('data'=>'HtmlTag'), array('tag' => 'td')),
                array('Label', array('tag' => 'td')),
                array(array('row' => 'HtmlTag'), array('tag' => 'tr'))
                ));

Is there a way to achieve what I want without extending the Zen开发者_开发知识库d_Form_Decorator_Label to pass additional option to the enclosing tag?


$from->setDecorators(array(
'ViewHelper',
'Description',
'Errors',
array(array('data'=>'HtmlTag'), array(
    'tag' => 'td'
)),
array('Label', array(
    'tag'   => 'td',
    'class' => 'labelcell'
    'tagClass' => 'YourClassNameHere' <- THIS IS WHAT WILL ADD TO LABEL WRAPPER

)),
array(array('row' => 'HtmlTag'), array(
    'tag' => 'tr'
)),

));


There is an option class. You should be able to define it in your config array, too. Try this:

$from->setDecorators(array(
    'ViewHelper',
    'Description',
    'Errors',
    array(array('data'=>'HtmlTag'), array(
        'tag' => 'td'
    )),
    array('Label', array(
        'tag'   => 'td',
        'class' => 'labelcell'
    )),
    array(array('row' => 'HtmlTag'), array(
        'tag' => 'tr'
    )),
));
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号