diff --git a/library/Zend/Form/Element/MultiCheckbox.php b/library/Zend/Form/Element/MultiCheckbox.php index 48fe7b62513..7fbe8fdffa8 100644 --- a/library/Zend/Form/Element/MultiCheckbox.php +++ b/library/Zend/Form/Element/MultiCheckbox.php @@ -71,6 +71,19 @@ public function setValueOptions(array $options) return $this; } + /** + * @param string $key + * @return self + */ + public function unsetValueOption($key) + { + if (isset($this->valueOptions[$key])) { + unset($this->valueOptions[$key]); + } + + return $this; + } + /** * Set options for an element. Accepted options are: * - label: label to associate with the element diff --git a/library/Zend/Form/Element/Select.php b/library/Zend/Form/Element/Select.php index 5b9f830955f..8b7d7069a87 100644 --- a/library/Zend/Form/Element/Select.php +++ b/library/Zend/Form/Element/Select.php @@ -84,6 +84,19 @@ public function setValueOptions(array $options) return $this; } + /** + * @param string $key + * @return self + */ + public function unsetValueOption($key) + { + if (isset($this->valueOptions[$key])) { + unset($this->valueOptions[$key]); + } + + return $this; + } + /** * Set options for an element. Accepted options are: * - label: label to associate with the element diff --git a/tests/ZendTest/Form/Element/MultiCheckboxTest.php b/tests/ZendTest/Form/Element/MultiCheckboxTest.php index 2bd6692d252..a2e7bae18e9 100644 --- a/tests/ZendTest/Form/Element/MultiCheckboxTest.php +++ b/tests/ZendTest/Form/Element/MultiCheckboxTest.php @@ -145,4 +145,32 @@ public function testDisableInputSpecification() $inputSpec = $element->getInputSpecification(); $this->assertArrayNotHasKey('validators', $inputSpec); } + + public function testUnsetValueOption() + { + $element = new MultiCheckboxElement(); + $element->setValueOptions(array( + 'Option 1' => 'option1', + 'Option 2' => 'option2', + 'Option 3' => 'option3', + )); + $element->unsetValueOption('Option 2'); + + $valueOptions = $element->getValueOptions(); + $this->assertArrayNotHasKey('Option 2', $valueOptions); + } + + public function testUnsetUndefinedValueOption() + { + $element = new MultiCheckboxElement(); + $element->setValueOptions(array( + 'Option 1' => 'option1', + 'Option 2' => 'option2', + 'Option 3' => 'option3', + )); + $element->unsetValueOption('Option Undefined'); + + $valueOptions = $element->getValueOptions(); + $this->assertArrayNotHasKey('Option Undefined', $valueOptions); + } } diff --git a/tests/ZendTest/Form/Element/SelectTest.php b/tests/ZendTest/Form/Element/SelectTest.php index 3951283e725..14db32344e7 100644 --- a/tests/ZendTest/Form/Element/SelectTest.php +++ b/tests/ZendTest/Form/Element/SelectTest.php @@ -207,4 +207,32 @@ public function testDisableInputSpecification() $this->assertArrayNotHasKey('validators', $inputSpec); } + public function testUnsetValueOption() + { + $element = new SelectElement(); + $element->setValueOptions(array( + 'Option 1' => 'option1', + 'Option 2' => 'option2', + 'Option 3' => 'option3', + )); + $element->unsetValueOption('Option 2'); + + $valueOptions = $element->getValueOptions(); + $this->assertArrayNotHasKey('Option 2', $valueOptions); + } + + public function testUnsetUndefinedValueOption() + { + $element = new SelectElement(); + $element->setValueOptions(array( + 'Option 1' => 'option1', + 'Option 2' => 'option2', + 'Option 3' => 'option3', + )); + $element->unsetValueOption('Option Undefined'); + + $valueOptions = $element->getValueOptions(); + $this->assertArrayNotHasKey('Option Undefined', $valueOptions); + } + }