7

Is it possible to render a section if checkbox is unchecked.

I tried this.

<apex:pageBlockSection columns="1" id="Test" >
  <apex:inputcheckbox value="{!test.Same_Address__c}" label="Same as Above" selected="True">
        <apex:actionSupport event="onchange" rerender="Test" />
    </apex:inputcheckbox>
    <apex:outputPanel rendered="{!test.Same_Address__c == false}"> <apex:inputField value="{!test.Contact_Surname__c}" />
    <apex:inputField value="{!test.Contact_First_Name__c}" />
    <apex:inputField value="{!test.Pos__c}" />
    <apex:inputField value="{!test.Addr__c}" />
 </apex:outputPanel>
</apex:pageBlockSection> 

Class code:-

        public with sharing class test{

        public Test__c test{get;set;}

            public Test(ApexPages.StandardController stdCtrl) {
            this.test=(Test__c)stdCtrl.getRecord();
           }

       }

Query:- I am just not able to see label... but the input field are visible .. i want to hide that as well. This field should be visible only if checkbox is unchecked.

I have added the set of field in output panel and this output panel is rendered only if checkbox is unchecked. But not working as expected.

The checkbox should be by default set to true when page loads. The user can uncheck it if he wishes and see more fields.

7
<apex:pageBlockSection columns="1" id="Test" >
 <apex:inputcheckbox value="{!test.Same_Address__c}" label="Same as Above">//removed selected=true
    <apex:actionSupport event="onchange" rerender="Test" />
</apex:inputcheckbox>
  <apex:outputPanel rendered="{!NOT(test.Same_Address__c)}"> 
    <apex:inputField value="{!test.Contact_Surname__c}" />//Use labels as previous answer from Marcel says
    <apex:inputField value="{!test.Contact_First_Name__c}" />
    <apex:inputField value="{!test.Pos__c}" />
    <apex:inputField value="{!test.Addr__c}" />
 </apex:outputPanel>
</apex:pageBlockSection>


public with sharing class test{

    public Test__c test{get;set;}

        public Test(ApexPages.StandardController stdCtrl) {
        this.test=(Test__c)stdCtrl.getRecord();
        this.test=true;//observe the change in this line.Added this for proper behaviour on load 
       }

   }

Here is the working code and I have added comments where necessary to the code to help you. Just remove selected=true at first place.

| improve this answer | |
4

There are several questions I see here. To see the label: change the inputfield to:

<apex:pageblocksectionitem>
    <apex:outputlabel value="{!$ObjectType.YOUR_OBJECT.fields.Contact_First_Name__c.label}" />
    <apex:inputField value="{!test.Contact_First_Name__c}" />
</apex:pageblocksectionitem>

To make the tickbox by default checked: In your controller after the getRecord -line put:

test.Same_Address__c = true;

For the rerender: the outputpanel around it sounds correct but you can not rerender an outputpanel that has an id and is not rendered. You should do something like this:

<apex:outputpanel id="Test">
    <apex:outputPanel rendered = "{!test.Same_Address__c == false}">
    .....
    </apex:outputPanel>
<apex:outputPanel>
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.