CakePHP3.1:禁用选择输入中的选项

时间:2016-01-03 13:24:29

标签: forms cakephp html-select disabled-input cakephp-3.1

我想在选择输入中禁用选项,所以我尝试了:

echo $this->Form->select("status", 
    [
    'options' => $status, 
    'value' => $order->status, 
    'label' => false, 
    'disabled' => [1, 2]
    ]);

但它不会在html代码中生成任何disabled语句。

我的错误是什么?

2 个答案:

答案 0 :(得分:2)

将属性设置为select选项的正确方法是传递一个这样的数组

$options = [
    [ 'text' => 'option 1', 'value' => 'value 1', 'disabled' => true],
    [ 'text' => 'option 2', 'value' => 'value 2', 'disabled' => true],
    [ 'text' => 'option 3', 'value' => 'value 3'],
    [ 'text' => 'option 4', 'value' => 'value 4']
];

echo $this->Form->select(
    'status', 
    $options, 
    ['value' => $order->status, 'label' => false]
);

答案 1 :(得分:1)

您应该使用FormHelper的输入功能并设置type =“select”
。我的样本(只有可选的三个)

$status = [1 => 'One', 2 => 'Two', 3 => 'Three'];
echo $this->Form->input("status", 
    [
    'type' => 'select',
    'options' => $status, 
    'label' => false, 
    'disabled' => [1, 2]
    ]
);
相关问题