How to disable to select one or more options from the drop-down list in cakephp?

I want to disable some options from the drop-down list, I have such an array

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)); 

anyone can help do this, it will be appreciated, thanks in advance.

+4
source share
4 answers

I think you should disable the options on the client side, i.e. from jQuery something like this

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

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

In addition to the answer from Moyde Ansari: You can use the .attr jquery function.

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

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

0
source

Try reinstalling the array as follows:

  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 just try this in your view:

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

Both of them do not require JavaScript or jQuery.

0
source

All Articles