2011-01-19 2 views
0

영문자 순으로 1000 개 이상의 id-> name 옵션이있는 선택 상자가있는 젠드 양식이 있습니다. 브라우저에서 렌더링하고 볼 때 Ch을 입력하면 그 옵션으로 이동합니다.첫 번째 글자를 기준으로 선택 상자 드롭 다운 목록에서 'selected'값 설정 -

양식을 초기화 한 후 처음 몇 글자를 통해 값을 선택하도록 설정하는 방법이 있습니까? 즉, $form->getElement('name')->setSelected('Ch') 또는 이와 유사한 것;

나는 setValue(34)와 내가

답변

1

(34) 그냥 코드 나 자신을 쓴 ID가 그 선택에 이름을 설정할 수 있다는 사실을 알고

class My_Form_Element_Select extends Zend_Form_Element_Select{ 
/** 
* Sets the the first option to start with certain letters to be selected 
* @param string $string The first few letters to search for 
*/ 
public function setSelected($string){ 
    $string = strtolower($string); 
    $options = $this->_getMultiOptions(); 
    $length = strlen($string); 
    foreach($options as $value => $option){ 
     if($string == strtolower(substr($option,0,$length))){ 
      $this->setValue($value); 
      break; 
     } 
    } 
    return $this; 
} 
관련 문제