简体   繁体   English

如何使用表单助手禁用cakephp中的select的单个选项?

[英]How to disable single option of a select in cakephp with form helper?

I need to disable a single particular option of a selectbox with form helper in cakephp. 我需要在cakephp中selectbox带有form helperselectbox的单个特定选项。 I am creating selectbox with below way : 我用以下方式创建选择selectbox

<?php 
    $options = array(1=>'Option 1',2=>'Option 2',3=>'Option 3')
    echo $this->Form->input('Model.field', array('options' => $options, 'empty' => '--select--')); 
?>

So now i need to disable Option 2 in selectbox like : 所以现在我需要在selectbox中禁用Option 2 ,如:

<select id="dropdown" name="dropdown">
    <option value="1">Option1</option>
    <option value="2" disabled="disabled">Option2</option>
    <option value="3">Option3</option>
</select>

So is there any disable property available in options array to disable single options? 那么在options数组中是否有任何禁用属性可以禁用单个选项?

Thanks in adavance. 谢谢,谢谢。

As per the reference of CakePHP . 根据CakePHP的参考。

Your can add disabled attribute like the below: 您可以添加以下disabled属性:

<?php 
    $options = array(1=>'Option 1',2=>'Option 2',3=>'Option 3')
    echo $this->Form->input('Model.field', array('options' => $options, 'disabled' => array(2), 'empty' => '--select--')); 
?>

Hope this help for you. 希望对您有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM