You need to sign in to do that
Don't have an account?
Dan 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:
Example code from the VF page:
Output checkbox list on the page:
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:
So in the above code the value 'First Option' is enabled and 'Second Option' is disabled.
@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.