Issues

ZF-5387: If there is a validation error, the Editor doesn't show its value again.

Description

Here is the form: $this->addElement( 'TextBox', 'Title', array( 'label' => 'News Title:', 'required' => true, 'validators' => array( array('NotEmpty', true), ), ) );

$this->addElement( 'Editor', 'Content', array( 'label' => 'News Content:', 'required' => true, 'height' => '150px', 'focusOnLoad' => true, 'validators' => array( array('NotEmpty', true), ), ) );

If there is a validation error, the Editor will set the value to "Array".

Because there are two elements named "Content", see the following html code:

And the solution is change the textarea element's id and name.

Open the Zend/Dojo/View/Helper/Editor.php: change the following code: protected function _normalizeEditorName($name) { if ('[]' == substr($name, -2)) { $name = substr($name, 0, strlen($name) - 2); $name .= '[Editor][]'; } else { $name .= '[Editor]'; } return $name; }

to:

protected function _normalizeEditorName($name) { if ('[]' == substr($name, -2)) { $name = substr($name, 0, strlen($name) - 2); $name .= '-Editor[]'; } else { $name .= '-Editor'; } return $name; }

Hope that helps.

Regard, Justin

Comments

Another solution is: Open the Zend/Dojo/View/Helper/Editor.php file:

change the following code: $html = '<input' . $this->_htmlAttribs($hiddenAttribs) . $this->getClosingBracket() . $this->textarea($textareaName, $value, $params, $attribs);

to:

$html = $this->textarea($textareaName, $value, $params, $attribs) .'<input' . $this->_htmlAttribs($hiddenAttribs) . $this->getClosingBracket();

Neither of the solutions work.

I am facing the same problem and am unable to capture the value type inside Editor.

If I hard code the value, like to 'something' below, then the server is able to capture the value correctly, on a valid post. using the following code: $form->editortab->getValue('content')

################### DOJO EDITOR ELEMENT
    $editorForm->addElement(
        'Editor',
        'content',
        array(
            'label'         => 'Content',
            'inheritWidth'  => 'true',
            'height'        => '230px',
            'width'         => '200px',
            'focusOnLoad'   => true,
            'required'      => $required,
            'value'         => 'some',

        )

Forgot to mention that when I hard-code, the value captured is only the text that I hard-coded (i.e. 'something') irrespective of what is actually typed on the UI

SOLVED :)

To make Zend Dojo Editor work do following to .../Zend/Dojo/View/Helper/Dijit.php

1- Inside _createGetParentFormFunction() return elementNode.domNode; instead of return elementNode;

However this solution only works for Firefox and not with the creepy Internet Explorer and the new kid called Google Crome

:(

This issue appears because "textarea" tag is used as base for editor. Dojo doesn't recommend this for several reasons (including XSS vulnerability). It is much better to use "div" tag as a base for editor.

Here is a helper subclass, which replaces "textarea" tag to "div". Solution automatically fixes this bug and several other issues caused by same reason.


class MyEditor extends Zend_Dojo_View_Helper_Editor
{
    public function textarea($id, $value = null, array $params = array(), array $attribs = array())
    {
        // it is a trivial copy-paste of Zend_Dojo_View_Helper_Textarea::textarea method
        // with replaced "textarea" tag to "div"

        if (!array_key_exists('id', $attribs)) {
            $attribs['id']    = $id;
        }
        $attribs['name']  = $id;
        $attribs['type']  = $this->_elementType;

        $attribs = $this->_prepareDijit($attribs, $params, 'textarea');

        $html = '
_htmlAttribs($attribs) . '>' . $value . "
\n"; return $html; } }