phpjqueryzend-frameworkzend-formzendx

ZendX Jquery Decorator


How use partial decorator in Jquery Element

I use this code for Form Element:

    $title = new Zend_Form_Element_Text('title');
    $title->setRequired(true)
            ->setAttrib('class', 'inputbox')
            ->setLabel('Title');
    $title->viewScript = 'RegElement.phtml';
    $title->setDecorators(
            array(
                array('ViewScript', array('class' => 'RegElement'))
            )
    );

But when i use Jquery Element i dont know how implement it:

    $datePicker = new ZendX_JQuery_Form_Element_DatePicker(
                    "datePicker1", array("label" => "Date:")
    );
    $datePicker->viewScript = 'RegElement.phtml';
    $datePicker->setDecorators(
            array(
                array('ViewScript', array('class' => 'RegElement'))
            )
    );

    //views/scripts/RegElement.phtml
    <li class="row <?php echo $this->class ?>">
        <div class="cont-error">
         <?php echo $this->formErrors($this->element->getMessages()); ?>
        </div>
        <div class="rowfields">
           <?php echo $this->formLabel($this->element->getName(),
                      $this->element->getLabel()) ?>
        <?php
            echo $this->{$this->element->helper}(
                 $this->element->getName(),
                 $this->element->getValue(),
                 $this->element->getAttribs()
             )
         ?>
        </div>
        <div class="hint"><?php echo $this->element->getDescription() ?></div>
    </li>

And display this error:

Warning: Exception caught by form: Cannot render jQuery form element without at least one decorator implementing the 'ZendX_JQuery_Form_Decorator_UiWidgetElementMarker' interface.

I need display datePicker with same format. but I dont know how implement this interface. thanks for your help.


Solution

  • It's because the regular ViewHelper decorator doesn't produce some proper code when used with ZendX_jQuery. You have to use one decorator which implement ZendX_JQuery_Form_Decorator_UiWidgetElementMarker and there is one provided. UiWidgetElement

      $datePicker->setDecorators(
                array(
                    'UiWidgetElement',
                    array('ViewScript', array('class' => 'RegElement'))
                )
        );