You need to sign in to do that
Don't have an account?
AncaD
Disable field in a VF page based on the values of a picklist
Hi,
I've created a VisualForce page and want to disable/enable a lookup field dynamically, based on the values selected in a picklist (i.e. when the value is selected in the picklist, I need the lookup field to be enabled or disabled, depending on the selection).
Any ideas on how to implement this?
Thank you!
Use actionSupport on your picklist to rerender the container of your lookup field. Something like this:
<apex:outputPanel id="thePanel"> <apex:inputField value="{!myObject__c.myPicklist__c}"> <apex:actionSupport event="onchange" action="{!doDisable}" rerender="thePanel"/> </apex:inputField> <apex:inputField value="{!myObject__c.myLookup__c}" rendered="{!shouldRender}"/> </apex:outputPanel> public void doDisable() { if (myObject__c.myPicklist__c == 'someValue') { shouldRender = false; } else { shouldRender = true; } }
All Answers
Hi..
Inputfield component doesnt support disabled attribute..
My idea for ur requirment is use rendered attribute..
Based on ur selection in selectlist u can display the lookup field
Use actionSupport on your picklist to rerender the container of your lookup field. Something like this:
<apex:outputPanel id="thePanel"> <apex:inputField value="{!myObject__c.myPicklist__c}"> <apex:actionSupport event="onchange" action="{!doDisable}" rerender="thePanel"/> </apex:inputField> <apex:inputField value="{!myObject__c.myLookup__c}" rendered="{!shouldRender}"/> </apex:outputPanel> public void doDisable() { if (myObject__c.myPicklist__c == 'someValue') { shouldRender = false; } else { shouldRender = true; } }