added validation support for optgroups #2331

Merged
merged 2 commits into from Sep 13, 2012

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
Zend Framework member

protected visibility, please.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@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
Zend Framework member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@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
Zend Framework member

Add whitespace around the else keyword, please.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@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
Zend Framework 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
@ghost Unknown pushed a commit that referenced this pull request Jul 14, 2013
@weierophinney weierophinney [#2331] CS fixes
- whitespace
- loop branching
- private -> protected
6752cb6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment