【问题标题】:CakePHP3.1: disable options in a select inputCakePHP3.1:禁用选择输入中的选项
【发布时间】:2016-04-07 05:31:27
【问题描述】:

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

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

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

我的错误是什么?

【问题讨论】:

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


【解决方案1】:

将属性设置为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]
);

【讨论】:

    【解决方案2】:

    您应该使用FormHelper的输入功能并设置type =“select”
    .我的样品(只能选择三个)

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

    【讨论】:

    • 工作答案... +1
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-12-21
    • 2018-07-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-15
    相关资源
    最近更新 更多