Changeset 1206

Show
Ignore:
Timestamp:
11/01/06 19:34:55 (2 years ago)
Author:
david
Message:

FPF: fixed population of multi-selects and fixed a situation where a fatal error could occur when populating multiple forms

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/filter/AgaviFormPopulationFilter.class.php

    r1196 r1206  
    190190        $p = $populate; 
    191191      } else { 
    192         $p = $populate[$form->getAttribute('id')]; 
     192        if(isset($populate[$form->getAttribute('id')]) && (($p = $populate[$form->getAttribute('id')]) instanceof AgaviParameterHolder)) { 
     193          $p = $populate[$form->getAttribute('id')]; 
     194        } else { 
     195          continue; 
     196        } 
    193197      } 
    194198       
     
    218222          $pname = $matches[1][0]; 
    219223           
    220           for($i = 0; $i < count($matches[2]); $i++) { 
     224          if($element->nodeName == 'select' && $multiple = $element->hasAttribute('multiple')) { 
     225            $count = count($matches[2]) - 1; 
     226          } else { 
     227            $count = count($matches[2]); 
     228          } 
     229          for($i = 0; $i < $count; $i++) { 
    221230            $val = $matches[2][$i]; 
    222231            if((string)$matches[2][$i] === (string)(int)$matches[2][$i]) { 
     
    338347           
    339348        } elseif($element->nodeName == 'select') { 
    340           $multiple = $element->hasAttribute('multiple'); 
    341349          // select elements 
    342350          // yes, we still use XPath because there could be OPTGROUPs 
    343351          foreach($xpath->query('descendant::' . $ns . 'option', $element) as $option) { 
    344352            $option->removeAttribute('selected'); 
    345             if($p->hasParameter($pname) && ($option->getAttribute('value') == $value || ($multiple && is_array($value) && in_array($option->getAttribute('value'), $value)))) { 
     353            if($p->hasParameter($pname) && ($option->getAttribute('value') === $value || ($multiple && is_array($value) && in_array($option->getAttribute('value'), $value)))) { 
    346354              $option->setAttribute('selected', 'selected'); 
    347355            }