function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

required fields enforced on cancel button with custom controller

I'm trying to build an edit page that contains a save and cancel button. The page has a required field and also has a custom controller.

The problem is that when I press the cancel button to invoke my cancel action, the cancel action is not invoked and instead the page displays an error that I must enter a value for the required field if I have no text in the field.

Is there a way to have this logic bypassed for a cancel action?


public PageReference cancelSendEmail(){
		string DocIDEmail = '';
		mailForm = false;
		return null;


<apex:form >

<label>Email address</label>
<apex:inputText value="{!addresses}" id="addresses" maxlength="80" required="true"/>

<apex:inputText value="{!Temp.Subject}" label="Subject" id="Subject" maxlength="80" required="true"/>

<apex:inputtextarea rows="8" cols="80" value="{!Temp.Body}" label="Body" id="Body"/>
<apex:commandButton value="cancel" action="{!cancelSendEmail}" immediate="true"/>
<apex:commandButton value="Send Email" action="{!send}">
  <apex:variable var="DVId" value="{!DocVs.Id}"/>
  <apex:inputHidden value="{!DVId}" id="theHiddenInput"/>

</apex:form >


That's very odd - I've got a page with several required fields and as long as I have the immediate="true" attribute set, I can execute a cancel action without any problems. Is it {!temp.subject} that throws the validation error?