_getChoices4Select(); $this->addElement( 'select', '0', [ 'label' => '', 'required' => true, 'multiOptions' => ['' => 'Please Select First Choice'] + $choices, ] ); $this->addElement( 'select', '1', [ 'label' => '', 'required' => true, 'multiOptions' => ['' => 'Please Select Second Choice'] + $choices, ] ); foreach (['0', '1'] as $name) { $this->getElement($name)->getDecorator('label')->setTagOption('class', 'hidden'); } return $this; } protected function _getChoices4Select() { $result = []; foreach ($this->getChoiceList() as $info) { $result[$info['id']] = $info['title']; } return $result; } public function isValid($data) { $isValid = self::isValidTrait($data); $isValidChoices = $this->_isValidChoices(); return $isValid && $isValidChoices; } public function isValidPartial(array $data) { $isValid = self::isValidPartialTrait($data); $isValidChoices = $this->_isValidChoices(); return $isValid && $isValidChoices; } protected function _isValidChoices() { $first = $this->getElement('0'); $second = $this->getElement('1'); if (!$first->hasErrors() && !$second->hasErrors() && $first->getValue() == $second->getValue()) { $second->addError('Choices should be different'); return false; } return true; } public function getChoiceList() { if (null === $this->_choiceList) { throw new \Exception('Required option is missing "' . __CLASS__ . '"->_choiceList'); } return $this->_choiceList; } public function setChoiceList($choiceList) { $this->_choiceList = $choiceList; return $this; } }