Reputation: 3218
how to set status "required" for Zend_Form_Element_Select when it has value "0"?
$country = new Zend_Form_Element_Select('wbm_country');
$country->setLabel('Select:')
->setRequired(true)
->addMultiOptions(array(0 => ' ----------- ') + $this->_countries_Select);
When wbm_country is 0 it doesn't show error at all.:(
Upvotes: 0
Views: 2962
Reputation: 16035
If you really want 0 to give an error you can use
$required = new Zend_Validate_NotEmpty ();
$required->setType ($required->getType() | Zend_Validate_NotEmpty::INTEGER | Zend_Validate_NotEmpty::ZERO);
$country = new Zend_Form_Element_Select('wbm_country');
$country->setLabel('Select:')
->addValidators (array ($required))
->addMultiOptions(array(0 => ' ----------- ') + $this->_countries_Select);
Upvotes: 3
Reputation: 5611
I guess you shouldnt put 0 as key, but '' (as being an empty string). But I'm not sure!
Upvotes: 3