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
Jim Riggio 1Jim Riggio 1 

Display fields after checkbox is checked

I have a request to display 4 fields when a Checkbox is displayed. I don't won't this fields to display unless the checkbox is checked in order to safe real estate.  I believe this has to be completed on a visualforce page, but not usre and don't know where to start. This will be displayed as a new section on the account page where several other sections reside. Is this possible without to much effort?
Ajay K DubediAjay K Dubedi
Hi Jim..
You can use something like this in this i am displaying contact first name , last name, email so you can change this code according to your requirement  

Class :
public class ContacControllerWrapper {
    public list<ContactWrapper>contactList{get; set;}
    public list<Contact>selectedContacts{get; set;}
    
    public ContacControllerWrapper(){
        contactList=new list<ContactWrapper>();
        for(Contact c:[select FirstName,LastName, Email from Contact LIMIT 10]){
           contactList.add(new ContactWrapper(c));
        }
    }
    public void ContactsSelected(){
        selectedContacts=new List<Contact>();
        for(ContactWrapper obj:contactList){
            if(obj.selected==true){
                selectedContacts.add(obj.ct);
            }
        }
    }
    public class ContactWrapper{
        public Contact ct{get; set;}
        public Boolean selected{get; set;}
        public ContactWrapper(Contact c){
            ct=c;
            selected=false;
        }
    }
}
vf page:
<apex:page controller="ContacControllerWrapper">
<apex:form >
    <apex:pageBlock >
    <apex:pageBlockSection >
        <apex:pageBlockTable value="{!contactList}" var="ctList">
            <apex:column >
            <apex:inputCheckbox value="{!ctList.selected}" onclick="valuetransfered();"/>
            </apex:column>
            <apex:column >
            <apex:outputField value="{!ctList.ct.FirstName}"/>
            </apex:column>
            <apex:column >
            <apex:outputField value="{!ctList.ct.LastName}"/>
            </apex:column>
        </apex:pageBlockTable>
    </apex:pageBlockSection>
    </apex:pageBlock>
    <apex:actionFunction name="valuetransfered" action="{!contactsSelected}" reRender="section1"/>
    <apex:pageBlock id="section1">
        <apex:pageBlockSection rendered="true">
            <apex:pageBlockTable value="{!selectedContacts}" var="selCt">
                <apex:column >
                <apex:outputField value="{!selCt.FirstName}"/>
                </apex:column>
                <apex:column >
                <apex:outputField value="{!selCt.LastName}"/>
                </apex:column>
                  <apex:column >
                <apex:outputField value="{!selCt.Email}"/>
                </apex:column>
            </apex:pageBlockTable>
        </apex:pageBlockSection>
    </apex:pageBlock>
</apex:form>
</apex:page>


 
Eswar Prasad@Sfdc11Eswar Prasad@Sfdc11
HI Jim Riggio

Pls see 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