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
AnchalGoelAnchalGoel 

Diable Select List

I am trying to disable a select List when the user checks a checkbox. I am running into the following problems.
 
a. The select option tag doesnt populate the options from the referenced field
b. The Select List box doesnt get disabled when i check the checkbox
Code:
<apex:inputfield value="{!case.Region__c}">
<apex:actionSupport event="onchange" action="{!regionSectionAction}" reRender="NewEmployeeRequest1"/></apex:inputField>&nbsp;&nbsp; <b>Region</b> &nbsp;&nbsp; 
<apex:selectList value="{!case.Regional_Location__c}" disabled="{!!noRegionSection}" >
<apex:selectOption value="{!case.Regional_Location__c}" itemLabel="{!case.Regional_Location__c}" />
</apex:selectList>

 
 
The same functionality works when i tried to disable a text box rather than a select List
 
Code:
<apex:inputfield value="{!case.Region__c}">
<apex:actionSupport event="onchange" action="{!regionSectionAction}" reRender="NewEmployeeRequest1"/></apex:inputField>&nbsp;&nbsp; <b>Region</b> &nbsp;&nbsp; 
<apex:inputtext value="{!case.Regional_Location__c}" disabled="{!!noRegionSection}" >
</apex:inputtext>

 

Thanks,


 
harlequinharlequin
  1. I think you should be using 'selectOptions' instead of 'selectOption'.
  2. The event handler for the checkbox should be event="onclick" and not event="onchange".
    Checkboxes don't have an onchange event.
AnchalGoelAnchalGoel

Hi,

I did that and the validation now seems to be working. But my options for the select list arent getting pulled from the custom object. The Select List is empty.

Code:
<apex:inputfield value="{!case.Region__c}">
<apex:actionSupport event="onclick" action="{!regionSectionAction}" reRender="NewEmployeeRequest1"/></apex:inputField>&nbsp;&nbsp; <b>Region</b> &nbsp;&nbsp; 
<apex:select list value="{!case.Regional_Location__c}" disabled="{!!noRegionSection}"
<apex:selectOptions value="{!case.Regional_Location__c}"/>
</apex:selectlist>


 Thanks,

harlequinharlequin

I must admit I don't use Select Lists too often, but according to the docs your 'case.Regional_Location__c' should be an array (List) of SelectOption classes, made up like this:

public List<SelectOption> getItems
{
    List<SelectOption> options = new List<selectOption>();
    options.add(new SelectOption('US', 'US');
    options.add(new SelectOption('CANADA', 'Canada');
    return options;
}

The first argument is the option's value and the second parameter is the option's display text, so I think you'll have to loop through your locations building up a SelectOption list.
Sorry I can't be of more help.