简体   繁体   English

如何禁用从cakephp的下拉列表中选择一个或多个选项?

[英]how to disable to select one or many option from dropdown list in cakephp?

I want to disable some options from dropdown list, i have an array like that 我想从下拉列表中禁用一些选项,我有一个这样的数组

  array(
'all' => 'ALL',
'skip1' => 'User Define Groups:',
(int) 43 => '--Usii Group2',
(int) 105 => '--Usii Mailing [ mailing list]',
(int) 106 => '--test [ mailing list]',
'skip2' => 'Dynamic Define Groups:'


i want to disable value of skip1 and skip2, if user click on skip1 and skip2 value it can't be select in dropdown list, this is my view file     


    echo $this->FormManager->input('view',array('label'=>'View ','type'=>'select','options'=>$viewGroup,'default'=>$default)); 

any one can help to do this, it will be appreciated, thanks in advance. 任何人都可以帮助做到这一点,我们将不胜感激,提前感谢。

I think you should disable options from client side, ie from Jquery something like this 我认为你应该从客户端禁用选项,即从Jquery这样的东西

HTML HTML

<select>
    <option value="all">ALL/option>
    <option value="skip1">User Define Groups:</option>
    <option value="43 ">--Usii Group2</option>
    <option value="105">--Usii Mailing [ mailing list]</option>
    <option value="106">--test [ mailing list]</option>
    <option value="skip2">'Dynamic Define Groups:</option>
</select>

JQuery JQuery的

$('option[value=skip1]').prop('disabled', true);
$('option[value=skip2]').prop('disabled', true);

To complement an answer from Moyed Ansari: You can use .attr jquery function. 为了补充Moyed Ansari的答案:你可以使用.attr jquery函数。

$('option[value=skip1]').attr('disabled', true);
$('option[value=skip2]').attr('disabled', true);

Use an array of arrays. 使用数组数组。

$values = array(
  'all' => 'all',
  'skip1' => array(
    5 => 'ex',
    6 => 'ex',
    7 => 'ex',
  ),
  'skip2' => array(
    5 => 'ex',
    6 => 'ex',
    7 => 'ex',
  )
)

See here: http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html#FormHelper::select 见这里: http//book.cakephp.org/2.0/en/core-libraries/helpers/form.html#FormHelper ::选择

Try with re-arrange the array by following way: 尝试通过以下方式重新排列数组:

 array(
      'all' => 'ALL',
      'skip1' => array(
           'name' => 'User Define Groups:',
           'value' => 'skip1',
           'disabled' => true
      )
      (int) 43 => '--Usii Group2',
      (int) 105 => '--Usii Mailing [ mailing list]',
      (int) 106 => '--test [ mailing list]',
      'skip2' => (
           'name' => 'Dynamic Define Groups:'
           'value' => 'skip2',
           'disabled' => true
      )
 )

Or you can simply try this on your view : 或者你可以在你的观点上试试这个:

echo $this->FormManager->input('view',array('label'=>'View ','type'=>'select','options'=>$viewGroup,'default'=>$default, 'disabled'=>array('skip1','skip2')));

Both of those do not require any JavaScript or jQuery. 这两个都不需要任何JavaScript或jQuery。

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

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