Hi,
Sometimes we find issues when we use <apex:commandButton> with both onClick and Action. We try to return false / true from our javascript method and expect things to be happen properly but sometimes it not happens. See below:-
<script>
function confirm(){
if(something condition){
return true;
}
return false;
}
</script>
<apex:commandButton value="Submit" action="{!CallAction}" onClick="return confirm();"/>
The above code does not call action sometimes..(Dont know why)...so if you change it with this, it will work:-
<apex:commandButton value="Submit" action="{!CallAction}" onClick="if(!confirm()) return false;"/>
The above code will work....Please don't ask why........
Thanks
Apex:commandButton and onClick issue...
Friday, October 2, 2009
by Aslam - The Alexendra
Posted in |
6 Comments »
Subscribe to:
Post Comments (Atom)
6 comments:
This worked for me. Thanks! --RP
If you take a look at the generated coded you'll see why this is. SalesForce appends the AJAX call to the onclick handler. So when you return true ( or anything else ) from the onclick the AJAX call never happens. By only returning when the confirm fails the correct behavior happens.
Good one..! Very helpful. And it worked for me. thanks to all
Thanks it helped
Big thanks for this tip. Using Winter 14 and this still is a bug.
Great! it worked for me too
Post a Comment