[SalesForce] Display InputText field when checkbox is checked

I am trying to display a textfield when 'Yes' checkbox is checked, but due to addition of lookup field value on VF page textfield is stopped displaying when I check the checkbox. That means only one textfield is showing either lookupfield or textfield when I check the checkbox. I need to show them both.

<apex:page standardController="Review__c" extensions="VFTestController" showHeader="false" standardStylesheets="false"> 
<apex:form >
<apex:pageBlock title=" Review">
<apex:pageblocksection >
           <apex:inputcheckbox value="{!chkBx}" label="Yes"> 
                <apex:actionSupport event="onchange" rerender="thePanel" action="{!click}"/>    
            </apex:inputcheckbox> 
           <apex:inputCheckbox label="No"/>  
</apex:pageblocksection><br></br>

If Yes..
<apex:pageblocksection >
 <apex:outputPanel id="thePanel">    
                <apex:pageBlockSectionItem rendered="{!displayInputputText}">
                    <apex:outputLabel value="Enter Text" />
                    <apex:inputText value="{!Review__c.X2Yes__c}"/>  
                </apex:pageBlockSectionItem>
            </apex:outputPanel>
</apex:pageblocksection>


Enter Contact Name:<br></br>
<apex:inputField value="{!Review__c.Contact__c}"/>
<br></br>
<div align="center" draggable="false" >
        <apex:commandButton action="{!save}" value="Submit"/>
</div><br></br>

</apex:pageBlock>
</apex:form>
</apex:page>

Controller Extentions:

 public Boolean displayInputputText{get;set;}
    public Boolean chkBx{get;set;}
    public String input{get;set;}       
    public PageReference click(){    
         if(chkBx){
             displayInputputText = true;
         }
         else{
             displayInputputText = false;
         }
         return null;
    }

Best Answer

You have kept the rendered attribute to a pageblocksectionitem so only that field is enabled on Check equals true.

Move that boolean to pageblocksection instead to enable both fields

<apex:pageblocksection rendered="{!displayInputputText}">
   <apex:outputPanel id="thePanel">    
      <apex:pageBlockSectionItem>
         <apex:outputLabel value="Enter Text" />
         <apex:inputText value="{!Review__c.X2Yes__c}"/>  
     </apex:pageBlockSectionItem>

     <apex:pageBlockSectionItem>
        <apex:outputLabel value="Enter Contact Name:" />
        <apex:inputText value="{!Review__c.Contact__c}"/>  
     </apex:pageBlockSectionItem>
   </apex:outputPanel>
</apex:pageblocksection>


Related Topic