function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Dan Olson 15Dan Olson 15 

How can I disable the clickability of a selectOption label?

I am building a 'List<SelectOption>' and populating it with 'new SelectOption's, then using it in an apex:selectCheckboxes construct to output a set of checkboxes on a VF page. When Salesforce generates the checkboxes, I see the <input> and <label> tags as I expect. However, some of the labels in a list are very long, and I want to disable the functionality of clicking the labels to change the status of the associated checkbox. It can lead to inadvertent setting or unsetting of the checkbox values. How can I disable the clickability? In straight HTML coding, I can set the onclick handler to return false, which prevents it from altering the checkbox value, but I have not been able to figure out how to implement that in this case, since I don't seem to have access to parameters of the <label> command.

Example coding from the controller:
dynamicSEPOptions = new List<SelectOption>();
dynamicSEPOptions.Add(new SelectOption('First', '</label>Short normal label<label>'));
dynamicSEPOptions.Add(new SelectOption('Second', '</label>This is a very long label, which should point out that it could lead to inadvertent setting of the checkbox value<label>'));
dynamicSEPOptions.Add(new SelectOption('Third', '</label>This is an even longer label, wrapping over several lines, which, regardless of the content of the text, should not be clickable to set the checkbox value because it doesn\'t conform to current web experience standards and can result in incorrect checkbox values<label>'));

Example code from the VF page:
<apex:selectCheckboxes value="<field name>" layout="pageDirection" >
     <apex:selectOptions value="{!dynamicSEPOptions}" />
</apex:selectCheckboxes>

Output checkbox list on the page:
Output example of checkboxes
ArmouryArmoury
In the controller you can set the disable feature like below..
 
dynamicSEPOptions.Add(new SelectOption('First', 'First Option', false));
dynamicSEPOptions.Add(new SelectOption('Second', 'Second Option', true));
So in the above code the value 'First Option' is enabled and 'Second Option' is disabled.
 
Dan Olson 15Dan Olson 15
Thanks for that input, but it's not quite what I was looking for. I still want to be able to check the boxes by clicking the boxes themselves, I just don't want clicks on the labels to affect the checkbox value. The default action is for a click on the label to invert the checkbox. Setting the disable feature prevents the checkboxes from being clickable also.
Allen ManamelAllen Manamel

@Armoury I want to do exactly what you have suggested. Basically disable a select option. I tried your code. It didn't work. Any help would be appreciated. Here is my code

 public List<SelectOption> getItems() {
        List<SelectOption> options = new List<SelectOption>(); 
        options.add(new SelectOption('First', 'First Option', false)); 
        options.add(new SelectOption(' ', ' ', true));
        options.add(new SelectOption('Second', 'Second Option',false)); 
        return options; 
    }  

My selectoption is null because I actually want to add a line between 'First' and 'Second' option. I don't know how to do that so I am adding an option in between and trying to make it disappear to fulfill the purpose but the option does not get disappear. There is no text but a radio button appears in between those two options.