added validation support for optgroups #2331

Merged
merged 2 commits into from Sep 13, 2012

Projects

None yet

3 participants

@jamescarr

Commits speak for themselves. Changed getOptionsValues() to extract nested values from option groups. This allows for proper validation of Selects that have optgroups in them.

@cgmartin

Looks good 👍

@weierophinney weierophinney commented on the diff Sep 13, 2012
library/Zend/Form/Element/Select.php
}
return $values;
}
+
+ private function getOptionValue($key, $optionSpec)
@weierophinney
weierophinney Sep 13, 2012 Zend Framework member

protected visibility, please.

@weierophinney weierophinney commented on the diff Sep 13, 2012
library/Zend/Form/Element/Select.php
@@ -175,9 +175,19 @@ protected function getValueOptionsValues()
$values = array();
$options = $this->getValueOptions();
foreach ($options as $key => $optionSpec) {
- $value = (is_array($optionSpec)) ? $optionSpec['value'] : $key;
- $values[] = $value;
+ if(is_array($optionSpec) && array_key_exists('options', $optionSpec)){
@weierophinney
weierophinney Sep 13, 2012 Zend Framework member

Add whitespace between if and opening paren, and between closing paren and opening brace.

@weierophinney weierophinney commented on the diff Sep 13, 2012
library/Zend/Form/Element/Select.php
@@ -175,9 +175,19 @@ protected function getValueOptionsValues()
$values = array();
$options = $this->getValueOptions();
foreach ($options as $key => $optionSpec) {
- $value = (is_array($optionSpec)) ? $optionSpec['value'] : $key;
- $values[] = $value;
+ if(is_array($optionSpec) && array_key_exists('options', $optionSpec)){
+ foreach ($optionSpec['options'] as $nestedKey => $nestedOptionSpec) {
+ $values[] = $this->getOptionValue($nestedKey, $nestedOptionSpec);
+ }
+ }else{
@weierophinney
weierophinney Sep 13, 2012 Zend Framework member

Add whitespace around the else keyword, please.

@weierophinney weierophinney added a commit that referenced this pull request Sep 13, 2012
@weierophinney weierophinney [#2331] CS fixes
- whitespace
- loop branching
- private -> protected
35a29d2
@weierophinney
Member

Incorporated feedback, and merged to release and master branches.

@weierophinney weierophinney merged commit 3cb169c into zendframework:master Sep 13, 2012

1 check passed

Details default The Travis build passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment