2

I have an apex:inputField control bound to a field of type picklist on a visualforce page. Like so:

<apex:inputField value="{!myObj.DependentPicklist__c}" required="true" />

Inexplicably it renders disabled and the HTML output is as seen below (some details have been omitted for sake of brevity):

<div class="condRequiredInput">
    <div class="requiredBlock"></div>
    <span>
        <select id="..." name="..." disabled=""> ... PICKLIST OPTIONS ... </select>
        <input type="hidden" name="..." value="__">
    </span>
</div>

My understanding is that apex:inputField has no disabled attribute. I searched for any JS code that might be manually disabling the input control to no avail. So my question is, what Salesforce built in functionality could possibly cause an apex:inputField bound to a picklist field to render with a disabled attribute?

1

I discovered that the picklist in question is dependent on another picklist's value. The picklist's values are being filtered by another's chosen value. There are two ways that I know of to check this. One is via the SF UI and the other is by looking at the .object file's XML in your project if you are using some IDE and deploying schema changes from your local.

Here is an example of what the the XML defining the picklist field in question might look like:

<CustomObject xmlns="http://soap.sforce.com/2006/04/metadata">
    ...
    <fields>
        <fullName>DependentPicklist__c</fullName>
        <description>This picklist field is dependent on another</description>
        <externalId>false</externalId>
        <inlineHelpText>Some help text</inlineHelpText>
        <label>Dependent Picklist</label>
        <picklist>
            <controllingField>ControllingPicklist__c</controllingField>
            <picklistValues>
                <fullName>Picklist Val 1</fullName>
                <controllingFieldValues>Controlling Picklist Val 1</controllingFieldValues>
                <controllingFieldValues>Controlling Picklist Val 2</controllingFieldValues>
                <default>true</default>
            </picklistValues>
            <picklistValues>
                <fullName>Picklist Val 2</fullName>
                <controllingFieldValues>Controlling Picklist Val 2</controllingFieldValues>
                <controllingFieldValues>Controlling Picklist Val 3</controllingFieldValues>
                <default>false</default>
            </picklistValues>
            <sorted>false</sorted>
        </picklist>
        <type>Picklist</type>
    </fields>
    ...
</CustomObject>

I find it easiest to look at the schema XML in the .object file. Locate the picklist field which is being disabled. Within the <fields> XML nodes look for <controllingField> node. The field API name specified here is the API name of the field controlling what options are available in the picklist. In my case since I added a new value to the controlling picklist field without updating the dependent picklist SF disabled the control by default since no options were available. To fix this I simply had to add a <controllingFieldValues> node containing the controlling picklist's new value for each option I wanted to make available. After adding this node to each desired picklist values and deploying the .object file the inputField control became enabled with options.

1
  • Don't forget to mark it as answer.
    – Saroj Bera
    Jun 20 '16 at 6:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.