When using addErrorMessages() the bug is in Zend_Form_Element::_getErrorMessages().
When we add error with Zend_Form_Element::addError() the following is executed:
/**
* Add an error message and mark element as failed validation
*
* @param string $message
* @return Zend_Form_Element
*/
public function addError($message)
{
$this->addErrorMessage($message);
$this->markAsError();
return $this;
}
Let's take a look at markAsError() function:
$messages = $this->getMessages();
$customMessages = $this->_getErrorMessages();
$messages = $messages + $customMessages;
if (empty($messages)) {
$this->_isError = true;
} else {
$this->_messages = $messages;
}
return $this;
The problem is in _getErrorMessages function. The resulting $message var, in case of Multi field will look like this:
$messages = array(
0 => array(
0 => 'My custom errormessage',
1 => 'My custom errormessage',
2 => 'My custom errormessage'
)
)
It's structure is unknown for Zend_View_Helper_FormErrors, therefore there are errors.
I strongly suggest to give full control over the method of validating Multi elements! As for now validators are run on each and every selected
value, but there is no way to validate THE WHOLE FIELD, nor give it a GLOBAL SINGLE custom error message. Current architecture does NOT allow i.e. to
create a Zend_Validate_Count which would throw error if less (or more) number of fields have been selected.
There has been a bug in addError some time ago, which affected Zend_Element::addError (#ZF-3852).
Don't know if this is a help for anybody.