ZF-3286: Zend_Form_Element_Multi should behave as enumerated type


Actualy I'm not sure if this is bug or feature, but I'd expect all elements extending Zend_Form_Element_Multi to work as enums.

Having this element:

$element = new Zend_Form_Element_Select('name');
$element->addMultiOption('foo', "FOO");
$element->addMultiOption('bar', "BAR");

Expected behaviour:

$element->isValid('foo'); // returns true
$element->getValue();     // returns "foo"

But I was a bit surprised that a value which is unlisted can be accepted and returned:

$element->isValid('unlisted-value'); // returns true
$element->getValue(); // returns "unlisted-value"

I know this can be solved by adding InArray validator. But I would expect it's (probably the main) purpose and default behaviour of these elements not to let through unavailable options. If this behaviour is realy so intended, I think there should be at least warning in manual that it's upon to developer to provide the check manually. This relates to Select, MultiSelect, MultiCheckbox and Radio elements.


Please evaluate and categorize as necessary.

Behavior added to trunk and 1.6 release branch. New flag, 'registerInArrayValidator' allows you to disable the functionality as desired.

Also did the same for the Dojo form elements.

Updating for the 1.6.0 release.