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.
任何一个人都可以帮忙做这件事,我们将感激不尽,提前谢谢。
4 个解决方案
#1
6
I think you should disable options from client side, i.e from Jquery something like this
我认为你应该禁用客户端的选项,I。来自Jquery的e
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);
#2
1
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);
#3
0
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::选择
#4
0
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。
#1
6
I think you should disable options from client side, i.e from Jquery something like this
我认为你应该禁用客户端的选项,I。来自Jquery的e
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);
#2
1
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);
#3
0
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::选择
#4
0
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。