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
amritamrit 

Hide and show the section of fields if the checkbox is true

Hi,

 

Here im trying to create vf page to create  multiple object records in a single VF page.Im able to display the records in the page .In VF page i have created section for account,account qualification ,contact,opportunity and task.It is working fine

 

 

Im trying to implement one more functionality says there is a checkbox in all sections.if i checkbox is true then it should display next section

eg: In account if  the checkbox is true then only account qualification section will display.I know it is possible through apex:actionsupport .Suggest me how can i use it here

 

Below mentioned is VF page and Controller

<apex:page controller="multirecords" tabStyle="Account">
<apex:form>
<apex:pageBlock >
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!save}"/>
</apex:pageBlockButtons>
<apex:pageBlockSection title="Enter Account Information">

<apex:inputField value="{!A.Name}"/>
<apex:inputField value="{!A.Phone}"/>

</apex:pageBlockSection>
<apex:pageBlockSection title="Enter Account Qualification">
<!--<apex:inputField value="{!AQ.name}" required="false"/>-->
<apex:inputField value="{!AQ.Product__c}" required="false"/>
<apex:inputField value="{!AQ.Status__c}" required="false"/>
<apex:inputField value="{!AQ.Sub_Status__c}" required="false"/>
</apex:pageBlockSection>
<apex:pageBlockSection title="Enter Contact Information">
<apex:inputField value="{!c.lastname}" required="false"/>
<apex:inputField value="{!c.firstname}" required="false"/>
<apex:inputField value="{!c.email}" required="false"/>
</apex:pageBlockSection>
<apex:pageBlockSection title="Enter Opportunity Information">
<apex:inputField value="{!O.name}" required="false"/>
<apex:inputField value="{!O.closedate}" required="false"/>
<apex:inputField value="{!O.stagename}" required="false"/>
</apex:pageBlockSection>
<apex:pageBlockSection title="Enter Activities">
<apex:inputField value="{!t.Type}" required="false"/>
<apex:inputField value="{!t.Subject}" required="false"/>
<apex:inputField value="{!t.Status}" required="false"/>
<!--<apex:inputField value="{!t.WhoId}" required="false"/>
<apex:inputField value="{!t.WhatId}" required="false"/>-->
<apex:inputField value="{!t.Description}" required="false"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>

 

public class multirecords {

public Account A {get; set;}
Public Contact C {get; set;}
Public Opportunity O {get; set;}
Public Account_Qualification__c AQ{get;set;}
public Task t{get;set;}
public multirecords()
{
A = new account();
C = new contact();
O = new opportunity();
AQ = new Account_Qualification__c();
t = new Task();
}

public PageReference Save()
{
insert A;

C.Accountid = A.id;


AQ.Account__c=A.Id;
insert AQ;
O.Accountid = A.id;

If (O.name != NULL || C.lastname != NULL)
{
insert O;
insert C;
}
t.WhoId=C.id;
t.WhatId=O.id;
insert t;
return new PageReference('/'+A.id);
}

public static testmethod void multirecords()
{
multirecords M = new multirecords();

Account A = new account(name = 'Test');
insert A;

Contact C = new contact(lastname = 'test', AccountId = A.id);
insert C;

}
}

 Any help would be greatly appreciated

 

Thanks

 

 

Best Answer chosen by Admin (Salesforce Developers) 
SurekaSureka

Hi,

 

Sample Example:

 

<apex:page standardController="Contact" extensions="SampleClass">
<apex:form>
<apex:inputField value="{!contact.Targeted__c}"/>    //Checkbox Field
<apex:actionSupport event="onclick" action="{!dispSect}" rerender="checkBx"/>

//Display the section once the checkbox is checked

<apex:outputpanel id="checkBx">
<apex:pageBlock rendered="{!(if(dispSectBool==true, true, false))}" id="pgBlock">
<apex:inputField value="{!contact.NewFeild__c}"/>
</apex:pageblock>
</apex:outputpanel>
</apex:form>
</apex:page>

 

 

    public boolean dispSectBool{get;set;}

public SampleClass(ApexPages.StandardController controller)
    {
        dispSectBool = false;
    }

    public pagereference dispSect()
    {
        dispSectBool = true;
        system.debug('asdfasdfasdf');
        return null;
    }

 

Thanks

All Answers

SurekaSureka

Hi,

 

Sample Example:

 

<apex:page standardController="Contact" extensions="SampleClass">
<apex:form>
<apex:inputField value="{!contact.Targeted__c}"/>    //Checkbox Field
<apex:actionSupport event="onclick" action="{!dispSect}" rerender="checkBx"/>

//Display the section once the checkbox is checked

<apex:outputpanel id="checkBx">
<apex:pageBlock rendered="{!(if(dispSectBool==true, true, false))}" id="pgBlock">
<apex:inputField value="{!contact.NewFeild__c}"/>
</apex:pageblock>
</apex:outputpanel>
</apex:form>
</apex:page>

 

 

    public boolean dispSectBool{get;set;}

public SampleClass(ApexPages.StandardController controller)
    {
        dispSectBool = false;
    }

    public pagereference dispSect()
    {
        dispSectBool = true;
        system.debug('asdfasdfasdf');
        return null;
    }

 

Thanks

This was selected as the best answer
amritamrit

Thanks Surekha for your reply .It s working

.12.12
 How can we do this if it is in using lightning component