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
RahulRahul 

Hi Friends, when Iam selecting Rating as Warm phone Number Input field should be displayed. I have achieved this using Standard controller but facing problems when doing it through extensions. Please find my code below.Need help

VF Page :-

<apex:page standardController="Account" extensions="acccontroller">
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection id="theform" columns="1">
 <apex:actionRegion >
 <apex:outputLabel >hvb :</apex:outputLabel>
       <apex:inputField value="{!acc.Rating}">
       <apex:actionSupport event="onchange" action="{!null}" rerender="myform"/>  
       </apex:inputField>
   </apex:actionRegion>
  <apex:outputPanel id="myform" > 
       <apex:outputPanel rendered="{!If(acc.Rating == 'Warm',true,false)}">
       <apex:outputLabel >hvb :</apex:outputLabel>
     <apex:inputField value="{!acc.phone}"/>
       </apex:outputPanel> 
   </apex:outputPanel> 
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>  
</apex:page>

Apex Class :-

public class acccontroller {
public account acc{get;set;}
    public acccontroller(ApexPages.StandardController controller) {

    }
}
Best Answer chosen by Rahul
Khan AnasKhan Anas (Salesforce Developers) 
Hi Sumit,

Greetings to you!

Please try the below code, I have tested in my org and it is working fine. Kindly modify the code as per your requirement.

Visualforce:
<apex:page standardController="Account" extensions="acccontroller">
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockSection id="theform" columns="1">
                <apex:actionRegion >
                    <apex:outputLabel >Rating :</apex:outputLabel>
                    <apex:inputField value="{!acc.Rating}">
                        <apex:actionSupport event="onchange" action="{!null}" rerender="myform"/>  
                    </apex:inputField>
                </apex:actionRegion>
                <apex:outputPanel id="myform" > 
                    <apex:outputPanel rendered="{!If(acc.Rating == 'Warm',true,false)}">
                        <apex:outputLabel >Phone :</apex:outputLabel>
                        <apex:inputField value="{!acc.phone}"/>
                    </apex:outputPanel> 
                </apex:outputPanel> 
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>  
</apex:page>

Controller:
public class acccontroller {
    
    public Account acc{get;set;}
    
    public acccontroller(ApexPages.StandardController controller) {
        acc = (Account) controller.getRecord();
    }
}

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas​​​​​​​

All Answers

Khan AnasKhan Anas (Salesforce Developers) 
Hi Sumit,

Greetings to you!

Please try the below code, I have tested in my org and it is working fine. Kindly modify the code as per your requirement.

Visualforce:
<apex:page standardController="Account" extensions="acccontroller">
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockSection id="theform" columns="1">
                <apex:actionRegion >
                    <apex:outputLabel >Rating :</apex:outputLabel>
                    <apex:inputField value="{!acc.Rating}">
                        <apex:actionSupport event="onchange" action="{!null}" rerender="myform"/>  
                    </apex:inputField>
                </apex:actionRegion>
                <apex:outputPanel id="myform" > 
                    <apex:outputPanel rendered="{!If(acc.Rating == 'Warm',true,false)}">
                        <apex:outputLabel >Phone :</apex:outputLabel>
                        <apex:inputField value="{!acc.phone}"/>
                    </apex:outputPanel> 
                </apex:outputPanel> 
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>  
</apex:page>

Controller:
public class acccontroller {
    
    public Account acc{get;set;}
    
    public acccontroller(ApexPages.StandardController controller) {
        acc = (Account) controller.getRecord();
    }
}

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas​​​​​​​
This was selected as the best answer
RahulRahul
Thank you for the help :)