You need to sign in to do that
Don't have an account?
Using checkbox to render a pageblocksection
I want to render a page block section depending on whether the user check a checkbox. I'm using action support tag to render the page block section on action"on lick". The page renders when I check it. But it doesntdisappear when I uncheck it?
here is theh VF page
<apex:outputPanel >
<apex:outputLabel value="Add Organization Affiliation?" for="theAff"/>
<apex:inputCheckbox value="{!renderAffiliation}" id="theAff"/>
<apex:actionSupport event="onclick" rerender="affsection"/>
</apex:outputPanel>
<apex:outputPanel id="affsection">
<apex:pageBlockSection title="Organization Affiliations" rendered="{!renderAffiliation}">
<apex:inputField value="{!affiliations.npe5__Organization__c}"/>
<apex:inputField value="{!affiliations.npe5__Description__c}"/>
<apex:inputField value="{!affiliations.npe5__Role__c}"/>
<apex:inputField value="{!affiliations.npe5__Status__c}"/>
</apex:pageBlockSection>
</apex:outputPanel>
THe controller get, set the renderAffiliation variable
public Boolean renderAffiliation{get; set;}
Try this:
<apex:outputLabel value="Add Organization Affiliation?" for="theAff"/> <apex:inputCheckbox value="{!renderAffiliation}" id="theAff"/> <apex:actionSupport event="onclick" rerender="affsection"/> </apex:outputPanel> <apex:outputPanel id="affsection"> <apex:pageBlockSection title="Organization Affiliations" rendered="{!renderAffiliation}"> <apex:inputField value="{!affiliations.npe5__Organization__c}"/> <apex:inputField value="{!affiliations.npe5__Description__c}"/> <apex:inputField value="{!affiliations.npe5__Role__c}"/> <apex:inputField value="{!affiliations.npe5__Status__c}"/> </apex:pageBlockSection> </apex:outputPanel>
I dont see the difference. Am I missing something?
THe code, render the section. but when i uncheck, it doest rerender adn remove the section.
PS: you may have seen my post. i made some changes to the code ( i copied an old version to the board)
I didn't see your updated code. I'm guessing one of these fields is required:
<apex:inputField value="{!affiliations.npe5__Organization__c}"/> <apex:inputField value="{!affiliations.npe5__Description__c}"/> <apex:inputField value="{!affiliations.npe5__Role__c}"/> <apex:inputField value="{!affiliations.npe5__Status__c}"/>
Monitor your debug log and add the tag apex:messages inside this panel:
<apex:outputPanel id="affsection"> <apex:messages/> <apex:pageBlockSection title="Organization Affiliations" rendered="{!renderAffiliation}">
Yes you are right, npe5__Organization__c is a required field in affiliations. So when I check the box, the section renders, but when I uncheck it the field npe5__ORganization__c displays a "is required" error and doesnt hide.
Also, the debug blog doesnt popup. It says "lo4javascript error: popup is blocked".. the debug log opens fine for other tabs.
Hiii,
I also try the same code that you have post for render the page on basis of checkbox. its working fine but it doesn't allow me enter any values in the input field of output panel. i.e. when i check the checkbox a pageblocksection is appear with some values but am not able to enter the values in these input fields..... Please tell me whts the problem. is anything missing from my side????
Thanks In Advance.