You need to sign in to do that
Don't have an account?
sfdc newbie
How to hide a picklist by selecting some value in another picklist?
I created some code like this. but i dont want to display type 2 field by default also. Could anyone please help out
<apex:page controller="ShowSectionController" tabStyle="Account">
<apex:form >
<Apex:actionFunction name="hideSection" action="{!hideSectionOnChange}" rerender="pg"/>
<apex:pageBlock id="pg">
<apex:pageBlockSection >
<apex:inputField value="{!acc.Type}" onchange="hideSection('{!acc.Type}')"/>
</apex:pageBlockSection>
<apex:pageBlockSection rendered="{!(!flag)}">
<apex:inputField value="{!acc.Type_2__c}"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
public class ShowSectionController
{
public Account acc{get;set;}
public boolean flag{get;set;}
public ShowSectionController()
{
acc = new Account();
flag = false;
}
public void hideSectionOnChange()
{
if(acc.Type == 'Value 1')
flag = false;
if(acc.Type != 'Value 1')
flag = true;
}
}
<apex:page controller="ShowSectionController" tabStyle="Account">
<apex:form >
<Apex:actionFunction name="hideSection" action="{!hideSectionOnChange}" rerender="pg"/>
<apex:pageBlock id="pg">
<apex:pageBlockSection >
<apex:inputField value="{!acc.Type}" onchange="hideSection('{!acc.Type}')"/>
</apex:pageBlockSection>
<apex:pageBlockSection rendered="{!(!flag)}">
<apex:inputField value="{!acc.Type_2__c}"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
public class ShowSectionController
{
public Account acc{get;set;}
public boolean flag{get;set;}
public ShowSectionController()
{
acc = new Account();
flag = false;
}
public void hideSectionOnChange()
{
if(acc.Type == 'Value 1')
flag = false;
if(acc.Type != 'Value 1')
flag = true;
}
}
Use the following code
In the above code the picklist2 is displayed on page load, if you change the value of picklist1 to another value except 'Value 1', then the picklist2 will hide.
if you want the other way change the <apex:pageBlockSection rendered="{!!flag}"> to <apex:pageBlockSection rendered="{!flag}">
Hope this helps.
Regards.
here as below:
<apex:inputField value="{!acc.Type_2__c}" rendered="{!setbooleanflag}"/>
set 'setbooleanflag' as false initially and flip it true when you change the other picklist value.
thanks,
http://www.forcexplore.com/2014/07/wrapper-class-in-salesforce.html
{
if(acc.Type == 'Value 1')
flag = false;
if(acc.Type != 'Value 1')
flag = true;
}
Thanks for all inputs
why this page is not present in my account layout
Like
<apex:page standardcontroller="Account" extensions="ShowSectionController" tabStyle="Account">
{
public Account acc{get;set;}
public boolean flag{get;set;}
public ShowSectionController(ApexPages.StandardController controller)
{
acc = new Account();
flag = false;
}
public void hideSectionOnChange()
{
if(acc.Type == 'Value 1')
flag = false;
if(acc.Type != 'Value 1')
flag = true;
}
}
we can see this like this in detail page [image: Inline image 2] Can't we diplay this like normal fields and that to reflect in edit page to please
Heres the link
https://help.salesforce.com/HTViewHelpDoc?id=fields_defining_field_dependencies.htm&language=en_US