Arun Jain
Arun Jain

Reputation: 5464

Disable some checkboxes in checkboxlist + FormHelper

I am rendering checkbox list; say 10 checkboxes using the following code:

<?php echo $this->Form->input('User.hobbies', array('options' => $hobbies_array, 'multiple' => 'checkbox'));?>

Now I want to disable some of those checkboxes before rendering the view. Means I do not want to use the javascript to disable some checkbox. Please suggest, is there any kind of option there by which we can provide the array of checkbox values to disable some of those checkboxes. Please suggest.

Upvotes: 0

Views: 509

Answers (2)

Arun Jain
Arun Jain

Reputation: 5464

There is no any kind of FormHelper method available yet which can take two arrays, one for checkboxlist and another one for disabling some of those checkboxes. You will have to make your own Helper class extended by the FormHelper class.

Upvotes: 1

Borislav Sabev
Borislav Sabev

Reputation: 4866

I am not sure if this actually works as I haven't got the time to check it out right now, but it seems that you can accomplish this whit FromHelper::inputs(). I suggest you try something like this:

$form->inputs(array(
        'name' => array('label' => 'custom label'),
        'hobbies' => array(
            'label' => 'custom label',
            'type' => 'checkbox',
            'multiple' => true,
            'options' => $options

     )
));

Where $options is an array of checkbox names with options:

$options = array(
   'Thing1' => array(
      'Value 1' => 'Label 1',
      'disabled' => true
   ),
   'Thing2' => array(
      'Value 2' => 'Label 3'
   )
);

I will also research this when I have the time, because the concept is very interesting to know. I do not know when will I have the time to do a bit of research, but I will post a comment or update my answer accordingly.

Upvotes: 0

Related Questions