1
我正在使用Cake的表單助手,它應該預先填充,當我設置$ this-> request-> data到我的控制器中的某個東西。它是爲普通的type =「text」輸入框預填充的,但不適用於type =「select」。有人知道爲什麼CakePHP常規輸入框預填充但不是選擇框?
如果我在我看來,PR($這個 - >請求 - >數據)我得到這樣的結果:
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->Form->input('PurchasingProductColor.name', array('type' => 'text', 'label' => 'Product Color', 'div' => false, 'placeholder' => 'Color Name', 'class' => 'input-medium', 'disabled' => 'disabled', 'empty' => true));?>
我試着去掉'empty'=> true並移除佔位符並刪除殘疾人,但沒有任何東西讓diff erence。
任何想法傢伙?謝謝。
編輯:
我剛剛結束了使用此。
<?=$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'] : ''))));?>
我失去了empty => true功能和禁用的功能,但我會通過javascript控制這些功能。
謝謝。
嘿。這個特定的表單項通過ajax/json填充,它們在頁面加載之前總是不會被調用。如果沒有加載選項,是否無法預先填充?順便說一句,我試着做'選擇'=>數組('是'=>'是','否'=>'不')只是作爲一個測試,即使它有選項,它仍然沒有預先填充,是那是因爲其中一個選項不是CB1230 SEASHELL? – user2278120
這是因爲select選項需要索引,例如'options'=> array('yes'=>'YES','no'=>'NO')當您提供yes索引時,會選擇YES。您可以使用JavaScript創建選項,然後選擇您的特定選擇。 – Anubhav
我在我的解決方案中進行了編輯,但是您的工作讓我想起了它,所以我會將其標記爲最佳答案。謝謝。 – user2278120