+ Start a Discussion
Rick MacGuiganRick MacGuigan 

How to render a command button.

How can I render and unrender the commandbutton "button1" based on my action support field being set to ToggleSelect='Personal Auto' ? Thanks. 

<apex:page standardController="Audit__c" showHeader="true">
<apex:variable var="audit" value="{!Audit__c}" />
<apex:variable var="ToggleSelect" value="{!audit.Audit_Sample_Type__c}" />
<apex:form id="form1">
<apex:pageBlock id="block1" title="Audit Sample Selection">
<apex:pageBlockButtons location="top">
<apex:commandButton value="Edit" action="{!Edit}"/>
<apex:commandButton value="Save" action="{!Save}"/>
<apex:commandButton value="Cancel" action="{!Cancel}"/> 
<apex:commandButton action="{!urlfor("/apex/PROD_Audit_Auto_PolicySample", null, [AccId=Audit__c.Id])}" value="New Sample" style="background:lightblue;color:blue" id="button1" rendered="{!audit.Audit_Sample_Type__c='Personal Auto'}"/>
</apex:pageBlockButtons>

<apex:PageblockSection columns="1" > 
<apex:PageBlockSectionItem > 
<apex:outputLabel value="Audit Type"/>
<apex:actionRegion >
<apex:inputField value="{!Audit__c.Audit_Sample_Type__c}">
<apex:actionSupport event="onchange" reRender="ajaxrequest, button1" /> 
</apex:inputField>
</apex:actionRegion>
</apex:PageBlockSectionItem>
</apex:PageblockSection>

<apex:outputPanel styleClass="sample" id="ajaxrequest">
<apex:pageBlockSection columns="1" id="section1" showHeader="false" title="General Auto Audit Information Section" rendered="{!ToggleSelect='Personal Auto'}">
<apex:inputField value="{!audit.Personal_Auto_Product__c}" />
</apex:pageBlockSection>

</apex:outputPanel> 
</apex:pageBlock>
</apex:form>
</apex:page>

All Answers

Rick MacGuiganRick MacGuigan
Thanks. wrapping an outputPanel aroung the buttons worked. The "New Sample" button renders when the action is true.

<apex:page standardController="Audit__c" showHeader="true">
<apex:variable var="audit" value="{!Audit__c}" />
<apex:variable var="ToggleSelect" value="{!audit.Audit_Sample_Type__c}" />
<apex:form id="form1">
<apex:pageBlock id="block1" title="Audit Sample Selection">
<apex:pageBlockButtons location="top">

<apex:outputPanel id="buttons">

<apex:commandButton value="Edit" action="{!Edit}"/>
<apex:commandButton value="Save" action="{!Save}"/>
<apex:commandButton value="Cancel" action="{!Cancel}"/> 
<apex:commandButton action="{!urlfor("/apex/PROD_Audit_Auto_PolicySample", null, [AccId=Audit__c.Id])}" value="New Sample" style="background:lightblue;color:blue" id="button1" rendered="{!audit.Audit_Sample_Type__c='Personal Auto'}"/>

</apex:outputPanel>
</apex:pageBlockButtons>

<apex:PageblockSection columns="1" > 
<apex:PageBlockSectionItem > 
<apex:outputLabel value="Audit Type"/>
<apex:actionRegion >
<apex:inputField value="{!Audit__c.Audit_Sample_Type__c}">
<apex:actionSupport event="onchange" reRender="ajaxrequest, buttons" /> 
</apex:inputField>
</apex:actionRegion>
</apex:PageBlockSectionItem>
</apex:PageblockSection>

<apex:outputPanel styleClass="sample" id="ajaxrequest">
<apex:pageBlockSection columns="1" id="section1" showHeader="false" title="General Auto Audit Information Section" rendered="{!ToggleSelect='Personal Auto'}">
<apex:inputField value="{!audit.Personal_Auto_Product__c}" />
</apex:pageBlockSection>

</apex:outputPanel> 
</apex:pageBlock>
</apex:form>
</apex:page>