+ Start a Discussion
Neeraj Sharma 103Neeraj Sharma 103 

If i checked the checkbox then custom fields will appear and if the checkbox is unchecked then custom field will not come

Hi

I am Beginner in Salesforce
I am trying to this Scenario but how to start i dont know 
So Please Help Me I am new In Salesforce
My Question is:
 my checkbox name is Display Amount when i clicked on checkbox  then one custom field is appear  field name is Amount and when unchecked the checkbox then field will be not appear
Please help me

Thanks in Advance
Neeraj Sharma
Best Answer chosen by Neeraj Sharma 103
RovRov
since you are new , refer to these few lines of code at a time. 
In the sample below, focus on the following - 

Standard Component : actionSupport
Attributes : event, rerender, rendered
<apex:page standardController="Account">

<apex:pageBlock id="theBlock">
<apex:form>
  <!-- Private__c is my custom check box field -->
  
      <apex:inputCheckbox value="{!Account.Private__c}">
          <apex:actionSupport event="onchange" rerender="theBlock"/>
      </apex:inputCheckbox>
  
  <!-- Domain_Name__c is my custom text field -->
  
      <apex:inputText value="{!Account.Domain_Name__c}" rendered="{!Account.Private__c ==true}"/>
  
</apex:form>    
</apex:pageBlock>
</apex:page>

Firstly, rendering means process of displaying the output. 

<apex:inputText value="{!Account.Domain_Name__c}" rendered="{!Account.Private__c ==true}"/>
 means,  the TextBox is displayed i.e rendered only when the checkbox is true. 

<apex:actionSupport event="onchange" rerender="theBlock"/> means, 
When the value of the checkbox changes, refresh only certain part of the page, and in this case it is called "theBlock"

for detailed explanation and understanding I would suggest you read 
https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_compref_actionSupport.htm

 

All Answers

RovRov
I am assuming you want to do this declaratively not programatically. If so, you cannot show and hide a text field  conditionally based on the checkbox value. However, you can create validation rule to force a user to enter a value in the Amount text field when the Display Amount is checked. for e.g if Display Amount is checked, the user must enter an Amount for the record to save.  If Display is not checked, its is ok to leave the Amount text field blank.  
Neeraj Sharma 103Neeraj Sharma 103
Rendered and reRendered is not perfect for this situation i can see at google for this situation rendered is used in vf page but i dont understand the code how to use rendered and reRendered in vf page if you know about reRendered and Rendered so please help me how to use in vf page?

Thanks 
Neeraj Sharma
Neeraj Sharma 103Neeraj Sharma 103
Hi

This is the code but i dont understand flow of code so please explain using my requirement in this code
please reply fast ASAP

thanks
Neeraj Sharma




<apex:page >
    
 <apex:pageBlock id="xxxpb1">

<apex:pageBlockSection>
                    
<apex:actionRegion >               

  <apex:inputField id="xxxif1" value="{!Object.picklistfieldapiname1}" required="true" >

     <apex:actionSupport event="onchange" rerender="xxxpb1" />
  </apex:inputField>

</apex:actionRegion>
                 
</apex:pageBlockSection>
               
<apex:pageBlockSection id="xxxpbs1" rendered="true">

 <apex:inputField id="xxxif2" value="{!Object.Fieldtobedisplayed1}" rendered="{!IF(Object.picklistfieldapiname1 ='picklist value 1' || lead.Buyer_Type__c ='picklist value 2' ,true,false)}"/>

</apex:pageBlockSection>

<apex:pageBlockSection id="xxxpbs2" rendered="true">

 
    <apex:inputField id="xxxif3" value="{!Object.Fieldtobedisplayed2}" rendered="{!IF(Object.picklistfieldapiname1 ='picklist value 3' || lead.Buyer_Type__c ='picklist value 4' ,true,false)}"/>  

     </apex:pageBlockSection>
     </apex:PageBlock>
</apex:page>
RovRov
since you are new , refer to these few lines of code at a time. 
In the sample below, focus on the following - 

Standard Component : actionSupport
Attributes : event, rerender, rendered
<apex:page standardController="Account">

<apex:pageBlock id="theBlock">
<apex:form>
  <!-- Private__c is my custom check box field -->
  
      <apex:inputCheckbox value="{!Account.Private__c}">
          <apex:actionSupport event="onchange" rerender="theBlock"/>
      </apex:inputCheckbox>
  
  <!-- Domain_Name__c is my custom text field -->
  
      <apex:inputText value="{!Account.Domain_Name__c}" rendered="{!Account.Private__c ==true}"/>
  
</apex:form>    
</apex:pageBlock>
</apex:page>

Firstly, rendering means process of displaying the output. 

<apex:inputText value="{!Account.Domain_Name__c}" rendered="{!Account.Private__c ==true}"/>
 means,  the TextBox is displayed i.e rendered only when the checkbox is true. 

<apex:actionSupport event="onchange" rerender="theBlock"/> means, 
When the value of the checkbox changes, refresh only certain part of the page, and in this case it is called "theBlock"

for detailed explanation and understanding I would suggest you read 
https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_compref_actionSupport.htm

 
This was selected as the best answer
Neeraj Sharma 103Neeraj Sharma 103
Hi   Rov

Now i am Understand the Difference between rerender, rendered  and know about Event attribute
this sample code is useful for me 

Thanku So  Much