How can a commandButton ignore validation for one particular required field?
I am working on a seemingly simple portal account page with the following markup:
<apex:page standardController="Contact" extensions="MyController">
<apex:form>
<apex:pageBlock>
<apex:pageBlockButtons>
<apex:commandButton action="{!save}" value="Update"/>
</apex:pageBlockButtons>
<apex:pageBlockSection title="Details" columns="2" id="details">
<apex:inputField value="{!Contact.LastName}" label="Contact Name" required="true"/>
<apex:commandButton action="{!updateContact}" value="Update Contact" rerender="details"/>
<apex:inputField value="{!Contact.Account.Name}" label="Account Name" required="true"/>
<apex:commandButton action="{!updateAccount}" value="Update Account" rerender="details"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
When "Update Contact" is clicked I want the server to only validate the first field. Conversely the "Update Account" button should only validate the second field. When the main "Update" button is clicked I want the entire page to be validated.
I am seeing 2 solutions in front of me but I guess I'm not sure how to utilize them properly:
- actionRegions
- multiple forms
The pageBlockButtons wants to be the direct child of the pageBlock. Therefore I cannot wrap it inside a form. Also if I wrap the buttons inside actionRegions that will bypass validation.