0

When I click on Cancel button that is part of the VF SLDS page, I get an error specifying that Last Name for contact is needed.How can I bypass the standard field validation? Here is my button:

<li class="slds-button-group-item">
        <apex:commandButton styleclass="slds-button slds-button--neutral slds-grow" value="Cancel" action="{!cancelNewContact}" immediate="true" />
</li>

This is the method I am calling from my custom controller:

public pageReference cancelNewContact(){
    pageReference cancelNewContact = donorSearchGMSURL;
   cancelNewContact.setRedirect(true);
return cancelNewContact;
}

Here is my SLDS VF Last Name field.

<div class="slds-form-element slds-form-element_horizontal">
    <label class="slds-form-element__label" for="text-input-id-1">
      <abbr class="slds-required" title="required">* </abbr>Last Name</label>
   <div class="slds-form-element__control">                                                                            
       <apex:inputField value="{! con.LastName }"/>
   </div>
</div>
  • Could I be seeing the problem because <apex:inputField value="{! con.LastName }"/> is bound to an Contact Object record? If I unbind it, it works. The funny part is that I have another standard required lookup field, but yet upon cancel, that button is not being flagged. – Ivo Dimov Jul 31 '19 at 19:38
0

Place the cancel button within an action region:

<apex:actionRegion>
  <apex:commandButton value="Cancel" action="{!cancel}" ... />
</apex:actionRegion>

Do not use immediate="true", as this will cause your code to not run (this mode only allows reRendering without meeting Visualforce validation for required fields).

| improve this answer | |
  • Thank you for the idea. I did follow your instructions, added the tags and removed immediate, but still the same result. The out of the box validation for Contact's last name is being invoked. – Ivo Dimov Jul 31 '19 at 17:49
0

You can actually use:

<apex:commandButton value="cancel" onclick="reload();" />

It doesnt need any apex method, you just need to refresh tab to cancel form. reload() does that.

| improve this answer | |
  • I need the apex method, because I am trying to send the user back to an earlier VF page, with assigned params in the URL. – Ivo Dimov Jul 31 '19 at 17:52
  • I also just for the test of it, I added onclick="reload()", and removed the call for the class, and the field validation is still being invoked. – Ivo Dimov Jul 31 '19 at 17:55

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.