2014-01-30 5 views
1

저는 Cake의 폼 도우미를 사용하고 있습니다. $ this-> request-> 데이터를 컨트롤러에 설정하면 미리 채워집니다. 일반 type = "text"입력 상자에는 미리 채워지지만 type = "select"에는 채워지지 않습니다. 왜 그런지 알아?CakePHP 일반 입력 상자는 미리 채워지지만 선택 상자는 채우지 못합니까?

Array 
(
    [EventInvoiceHardsurface] => Array 
    (
     [id] => 7868 
     [expediting_notes] => Fake expiditing notes 
     [installation_notes] => Fake installation notes. 
    ) 

    [PurchasingProduct] => Array 
    (
     [style_number] => BDP 
     [style_name] => DUNDEE PLANK 3 1/4 
    ) 

    [PurchasingProductColor] => Array 
    (
     [name] => CB1230 SEASHELL 
    ) 

) 

      <?=$this->Form->input('PurchasingProductColor.name', array('type' => 'select', 'label' => 'Product Color', 'div' => false, 'placeholder' => 'Color Name', 'class' => 'input-medium', 'disabled' => 'disabled', 'empty' => true));?> 

을 미리 채울하지 않습니다하지만이

을 수행

는 나는이 결과를 얻을 내보기에 ($ this-> 요청 -> 데이터)를 홍보하는 경우

      <?=$this->Form->input('PurchasingProductColor.name', array('type' => 'text', 'label' => 'Product Color', 'div' => false, 'placeholder' => 'Color Name', 'class' => 'input-medium', 'disabled' => 'disabled', 'empty' => true));?> 

'빈'=> 참을 제거하고 자리 표시자를 제거하고 비활성화를 제거하려고했지만 그 중 어떤 것도 diff로 만들지 않았습니다. 예.

아이디어가 있으십니까? 감사.

편집 :

나는 방금 이것을 사용했다.

      <?=$this->Form->input('PurchasingProductColor.name', array('type' => 'select', 'label' => 'Product Color', 'div' => false, 'placeholder' => 'Color Name', 'class' => 'input-medium', 'options' => array((!empty($this->request->data['PurchasingProductColor']['id']) ? $this->request->data['PurchasingProductColor']['id'] : '') => (!empty($this->request->data['PurchasingProductColor']['name']) ? $this->request->data['PurchasingProductColor']['name'] : ''))));?> 

나는 빈 => 참 기능 및 사용 불가능한 기능을 잃지 만 자바 스크립트를 통해 이러한 기능을 제어합니다.

감사합니다.

답변

0

당신은 옵션

<?=$this->Form->input('PurchasingProductColor.name', 
array('type' => 'select', 'label' => 'Product Color', 'div' => false, 
'placeholder' => 'Color Name', 'class' => 'input-medium', 
'disabled' => 'disabled', 'empty' => true,'options'=>$optionsList));?> 

$ optionsList 다음은 특정 선택을 미리 선택합니다 선택 상자에 대한 옵션의 목록입니다을 제공해야합니다.

+0

안녕하세요. 이 특정 양식 항목은 페이지 로딩 전에 항상 호출되지 않는 ajax/json을 통해 채워집니다. 이미 옵션을로드하지 않고 미리 채울 방법이 없습니까? Btw, 나는 '옵션'=> 배열 ('예'=> '예', '아니오'=> '아니오')를 테스트 해 보았습니다. 미리 채워지지 않았던 옵션이 있었지만 옵션 중 하나가 CB1230 SEASHELL이 아니기 때문에? – user2278120

+0

예를 들어 'options'=> array ('yes'=> 'YES', 'no'=> 'NO')와 같이 선택 옵션이 필요합니다. javascript를 사용하여 옵션을 만든 다음 특정 선택 항목을 선택할 수 있습니다. – Anubhav

+0

내 솔루션에서 편집했지만 내 역할이 도움이되었으므로 최선의 답변으로 표시하겠습니다. 감사. – user2278120