You need to sign in to do that
Don't have an account?
How to do confirmation dialog then call method in custom cntrlr then go to page returned by method?
I want to put up your typical "Are you sure?" confirmation dialog box. Then if the user says "Yes" call a method in my customer controller and have the user end up on the page of the page reference returned by that controll.er
If I use <actionFunction> I just end up back ont he same page. What I tried is shown below.
I thought about doing something like window.top.location="{!URLFOR(save)}"; But it doesn't know what "save" is.
Any ideas?
<apex:actionFunction action="{!save}" name="doSaveAction"/>
<script>
function doSaveFunc(){
if ( confirm('The status is Work in Progress, Cancel, Needs Approval, Customer Rejected, or Internal Only. Are you sure you want to Create a Customer PO from this Cost Proposal?' )) {
doSaveAction();
}
}
</script>
...
<apex:commandButton onclick="Javascript:doSaveFunc();" value="Save"/>
You have to return from onclick:
<apex:commandButton action="{!save}" onclick="return confirm('are you sure?');" value="Save" />
Also, if you are using this button to save I'd recommend getting rid of the immediate="true" attribute since this skips all of the field validation on your page.
All Answers
I found this thread...http://community.salesforce.com/sforce/board/message?board.id=Visualforce&message.id=4096&query.id=347899#M4096
which says to try--
I tried that and it doesn put up the dialog but when I hit cancel, it still calls the method in the controller. This is what I tried--
<apex:commandButton action="{!save}" onclick="confirm('are you sure?');" value="Save" immediate="true"/>
You have to return from onclick:
<apex:commandButton action="{!save}" onclick="return confirm('are you sure?');" value="Save" />
Also, if you are using this button to save I'd recommend getting rid of the immediate="true" attribute since this skips all of the field validation on your page.
This is a great response, thanks! I was struggling with the same issue.
I was also wondering if there was a way of having a confirmation box pop up conditional on certain fields? i.e. if a certain field on the Opportunity said that the deal was renewable, a dialog box in a visualforce page would pop-up when a button was pressed.
With thanks,
Andy