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
LoneStar69LoneStar69 

rendering section on checkbox selection

Hi Guys!!!

Adding code to already existing page using Cases obj.
Trying to show/hide fields using checkbox selection.
Thanks for your help!!!

<apex:pageBlockSectionItem id="SPContent">                                
                     <apex:inputField required="true"  value="{!c.SP_Topics__c}"  id="sptopics"   />
            </apex:pageBlockSectionItem>    
    
<apex:actionRegion>
    <apex:inputCheckbox value="{!c.SP_Selection__c}" id="SP" >
         <apex:actionSupport event="onchange" reRender="SPContent" status="status" />
         </apex:inputCheckbox>
     </apex:actionRegion>

     <apex:pageBlockSectionItem id="NonSPContent">
                       <apex:inputField required="true" value="{!c.Product__c}"  id="prd" />
               <apex:inputField required="true" value="{!c.Product_Type__c}"  id="ptype" />
         </apex:pageBlockSectionItem>

     <apex:actionRegion>
    <apex:inputCheckbox value="{!c.Non_SP_Selection__c}" id="NonSP" >
         <apex:actionSupport event="onchange" reRender="NonSPContent" status="status" />
         </apex:inputCheckbox>
     </apex:actionRegion>
Andy BoettcherAndy Boettcher
Wrap your whole section in an apex:outputPanel and rerender THAT.  You cannot directly rerender a component after the DOM has loaded, you can rerender a PARENT section which will rerender what you're trying to actually do.  =)
Shrikant BagalShrikant Bagal
Please try following code:

 
<apex:pageBlockSectionItem id="SPContent">                                
                     <apex:inputField required="true"  value="{!c.SP_Topics__c}"  id="sptopics"   />
            </apex:pageBlockSectionItem>    
    

    <apex:inputCheckbox value="{!c.SP_Selection__c}" id="SP" >
         <apex:actionSupport event="onchange" reRender="SPContent" status="status" />
         </apex:inputCheckbox>
  

     <apex:pageBlockSectionItem id="NonSPContent">
                       <apex:inputField required="true" value="{!c.Product__c}"  id="prd" />
               <apex:inputField required="true" value="{!c.Product_Type__c}"  id="ptype" />
         </apex:pageBlockSectionItem>

    
    <apex:inputCheckbox value="{!c.Non_SP_Selection__c}" id="NonSP" >
         <apex:actionSupport event="onchange" reRender="NonSPContent" status="status" />
         </apex:inputCheckbox>

 
Eswar Prasad@Sfdc11Eswar Prasad@Sfdc11
HI Mairuz Khumer,

Try this below code what ever requirement written in above i done here,Example i can taken account field if what ever fields if you want you can take it ok.any query ask me
visualforce page
<apex:page Controller="coachingcontroller" id="page" >
  <apex:form id="form" >
    <apex:pageblock id="pb" >
      <apex:pageblockSection > 
      <apex:pageblockSectionItem >
         <apex:inputCheckbox value="{!chbox}">
              <apex:actionSupport event="onclick" action="{!chboxaction}"/>
                </apex:inputCheckbox>
           <apex:outputlabel value="Screenshot"/>
        </apex:pageblockSectionItem> 
          <apex:inputfield id="id1" value="{!acc.name}"  rendered="{!file1ren}"/>                                       
        <apex:pageblockSectionitem >
         &nbsp;<apex:outputlabel value="Additional Screenshot (Optional)"/>
         </apex:pageblockSectionitem>
        <apex:pageblockSectionitem >         
          <apex:inputfile id="id1" value="{!acc.phone}"  rendered="{!file2ren}"/>                                    
        </apex:pageblockSectionitem>
  </apex:pageblockSection>
 </apex:pageblock>
</apex:form>  
</apex:page>


controller:

public with sharing class coachingcontroller {
  public coachingcontroller(){
  file1ren=false;
  file2ren=false;
  }

    public Boolean file2ren { get; set; }

    public Boolean file1ren { get; set; }

    public Boolean chbox { get; set; }
    
    public Account acc {get;set;}

    public PageReference chboxaction() {
    if(chbox==true){
    file1ren=true;
    file2ren=true;
    }
    else{
    file1ren=false;
    file2ren=false;
    }
        return null;
    }

}


If you get the answer, please mark it as the correct answer. It will be a help to others who are facing the same problem later.

Regards
Eswar Prasad
LoneStar69LoneStar69
@Eswar Prasad - i am trying to accomplish this without touching the controller..coz...i need to achieve the test coverage again later.

@Andy, @Shrikant
No matter what i do, i cannot see the fields on the vf page.

if i say,
<apex:inputField required="true"  value="{!c.SP_Topics__c}"  id="sptopics"   />
or,
<apex:inputCheckbox value="{!c.SP_Selection__c}" id="SP" >

These fields do exist on the Case object.
Can't see it on the page, am i missing something?