How can I use zend form decorator to render errors inside my paragraph tag wrapping label and input

StackOverflow https://stackoverflow.com/questions/7960363

سؤال

I would like to render the following markup:

<div class="row">
<p>
  <label>Your Name</label>
  <input type="text" class="text_field" name="name">
  <ul class="errors">
    <li>Waarde is vereist en kan niet leeg worden gelaten</li>
  </ul>  
</p>
</div>

This is my Zend form element + decorator:

$this->addElement('text', 'name', array(        
            'label' => 'Naam:',
            'class' => 'text_field',
            'required' => true,
            'decorators' => array(
                'ViewHelper',
                'Label',
                'Errors',
                array(array('row' => 'HtmlTag'), array('tag' => 'p')),
                array(array('content' => 'HtmlTag'), array('tag' => 'div', 'class' => 'row'))
            )));

But this always renders the ul list below the p tag and never inside. It also adds an additional p tag below the list.

<div class="row">
  <p>
    <label class="required" for="name">Naam:</label>
    <input type="text" class="text_field" value="" id="name" name="name">
  </p>
  <ul class="errors">
    <li>Waarde is vereist en kan niet leeg worden gelaten</li>
  </ul>
  <p></p>
</div>

What am I doing wrong?

هل كانت مفيدة؟

المحلول

Found it! My stupid mistake. I did only check the final rendered output in my browser. I am using a template which also loads javascript and this changes the DOM which creates the unwanted result.

So the first decorator setup was working correct.

نصائح أخرى

Try to do the following:

$this->addElement('text', 'name', array(        
            'label' => 'Naam:',
            'class' => 'text_field',
            'required' => true,
            'decorators' => array(
                'ViewHelper',
                'Label',
                'Errors',
                array(array('content' => 'HtmlTag'), array('tag' => 'p')),
                array(array('content' => 'HtmlTag'), array('tag' => 'div', 'class' => 'row'))
            )));
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top