Hey all. I have a feeling the answer to my question is simply 'no, not possible', but I thought I'd check. I have some custom modules with forms. In one module I need to list all available items with check boxes for the user to select or de-select. At times, however, one or more check boxes in a long list will need to be disabled. (ie: the user cannot check or un-check the box, but its still important for the box and item to be listed.) Ideally, of course, the text box and description would be grey or something different. But in any case it's not obvious to me if this is possible. In searching I see a discussion about this in 7 development, so my assumption is its not yet available. Any way to make this happen? I'm in 5.7 now; planning to migrate to 6.x in about 2 months. Thanks in advance for the help.

Cheers,
K

Comments

crookednumber’s picture

kxerc’s picture

Thanks Crooked. Yeah, I've tried using 'disabled', but I can't seem to apply it to just one item in an array of checkboxes. For instance. Say I had a list of fruit; I don't, but say I did. The listed fruit are all part of the same form item call "fruit". So I have a form element of X check boxes where the number checkboxes and description of each is associated with an array.

So in the form the fruit item would look something like this

$form['fruit'] = array(

'#title' => t('Select Fruit'),
'#type' => 'checkboxes',
'#options' => $fruit_id,
'#disabled' => $fruit_available,
'#default_value' => $fruit_type

);

$fruit_id and $fruit_type are both arrays created through a database query and loop. I've tried doing the same with disabled, but no luck. Seems to ignore disabled as an array. If I set '#disabled' to simple true(not an array), all the boxes become greyed out -- disabled. I want to target just one or two items in the entire list.

To create the disabled array, I loop through a query like this:

while(.......){

if ($data->available <= 0){
$fruit_available[$data->fruit_id] = "FALSE";
}else{
$fruit_available[$data->fruit_id] = "TRUE";
}

}

Thanks in advance for the assistance.

crookednumber’s picture

Ah-ha. Take a look at:

http://api.drupal.org/api/file/developer/topics/forms_api_reference.html/5

http://api.drupal.org/api/file/developer/topics/forms_api_reference.html...

You can create one large element of '#type' => 'checkboxes'

or a number of individual elements of '#type' =>'checkbox' (singular)

In the first case, '#disabled' => TRUE will grey out all of the checkboxes. In the second, it would only grey out that particular checkbox. Using '#type' =>'checkbox' will require more work, and you 'll have to change your loop, but it should give you the level of control you're looking for.

kxerc’s picture

That did the trick. Mucho thanks!