+ Start a Discussion
KrishnadasKrishnadas 

Command Button not working properly

Hi,

I have created a visualforce page and a have also create a controller class for it.
I have created a command button for 'Cancel' in the Visualforce page. The action refers to a pagereference method in the controller class.
The pagereference method performs the function of redirecting to a different page of my choice. Redirect is set to true.
I encounter a problem with this in one scenario.
There is an input field in the visualforce page which is a lookup to different object. If I type something in the text space instead of selecting from the list and then click on Cancel, it does not work it stays in the same page and throws an error. Once I delete the text the Cancel button works.
What is happening? How do I get the Cancel to work all times.

Thanks
Krishnadas
Steadfast Global
www.steadfastglobal.com
Best Answer chosen by Admin (Salesforce Developers) 
wesnoltewesnolte

Hey

 

It's tough to say without seeing the code or error but I'd guess you need to use the immediate attribute of the commandbutton i.e.

 

<apex:commandButton immediate="true" ... />

 

Setting this stops the form from validating when submitting.

 

Cheers,

Wes 

All Answers

wesnoltewesnolte

Hey

 

It's tough to say without seeing the code or error but I'd guess you need to use the immediate attribute of the commandbutton i.e.

 

<apex:commandButton immediate="true" ... />

 

Setting this stops the form from validating when submitting.

 

Cheers,

Wes 

This was selected as the best answer
KrishnadasKrishnadas

Hi Wes,
 
Setting Immediate attribute to true was all that was required. Once done the Cancel button is working fine.
 
Thanks
Krishnadas
Steadfast Global
www.steadfastglobal.com