Let's say I have an object named Device__c. This has a picklist field named Type__c, which has two values: Laptop and Mobile.
Upon selecting Laptop, a picklist named Brand__c must be displayed. Brand__c picklist field contains two values: Apple and Acer.
Upon selecting Apple, a lookup field named Models__c must be displayed.
My question is, how can I filter this lookup field with such controlling picklist fields using Apex and visualforce?
By the way, here's my code:
vf page
<apex:page standardController="Device__c">
<apex:form >
<apex:pageblock >
<apex:selectList label="Device Type:" value="{!Device__c.Type__c}" size="1">
<apex:actionSupport event="onchange" reRender="b1" status="status"/>
<apex:selectOption itemValue="--None--" itemLabel="--None--"/>
<apex:selectOption itemValue="Laptop" itemLabel="Laptop"/>
<apex:selectOption itemValue="Mobile" itemLabel="Mobile"/>
</apex:selectList>
<apex:actionStatus startText="applying value..." id="status"/> <br/>
<apex:pageBlockSection id="b1">
<apex:selectList label="Brand" value="{!Device__c.Brand__c}" size="1">
<apex:selectOption itemValue="Apple" itemLabel="Apple"/>
<apex:selectOption itemValue="Acer" itemLabel="Acer"/>
</apex:selectList>
<apex:inputField value="{!Device__c.Models__c}" rendered="{!Device__c.Type__c='Laptop'}"/>
<apex:inputField value="{!Device__c.Device_Brand__c}" rendered="{!Device__c.Type__c='Laptop'}"/>
</apex:pageBlockSection>
</apex:pageblock>
</apex:form>
</apex:page>
Type__c
andBrand__c
are picklists, you can directly put the options in object definition. You don't need to put those in VF page. And what is the fieldDevice_Brand__c
stands for?