You need to sign in to do that
Don't have an account?
wt35
apex:commandButton : Confirm pop-up box before proceeding
Hi community,
I have a button on which I want to include a warning message, that is, when the user clicks on the button, a message appears asking if he/she wants to continue...
This is where I have gotten so far, when I click on the button I do have the message popping up and asking if I want to continue, however the change() action is called even if I close this window...I want the processing to take place only if the user clicks OK...
Thanks you!
<apex:page controller="HelloWorld"> <apex:form > <apex:commandButton value="Warning" onclick="javascript:window.alert('Do you want to proceed?');" action="{!change}"/> </apex:form> </apex:page>
Hi,
You need to add return infront of confirm.So when u click on ok it returns true and call action method otherwise do nothing.
uor code replace with the following:
<apex:commandButton value="Warning" onclick="return confirm('Do you want to proceed?');" action="{!sort}"/>
Please let me know if u have any query on same and if this post helps u please throw KUDOS by click on star at left.
All Answers
Hi,
Instead of using window.alert('Do you want to proceed?'), use window.confirm(''Do you want to proceed?') and your problem should be solved.
Let me know if you have any question about above.
Happy to help you!
The issue remains the same.
After some digging, it seems I need to use the actionFunction tag to perform validation first in JS and then launch my controller method.
However it seems my controller method is not called...
VF:
Apex method:
Hi,
You need to add return infront of confirm.So when u click on ok it returns true and call action method otherwise do nothing.
uor code replace with the following:
<apex:commandButton value="Warning" onclick="return confirm('Do you want to proceed?');" action="{!sort}"/>
Please let me know if u have any query on same and if this post helps u please throw KUDOS by click on star at left.
Hi,
No need to use action function i'll provide u the solution above uor latest post please try the same.
Simple and efficient.
Thanks!
Puja, not sure if you still can help me but now I implemented this logic into my real VF Page (which much more advanced that the frist example) and it is not working... I am wondering if it is because I have added an apex:param inside the button:
When I click on my button I do get a confirmation pop-up, however the Apex action is not executed....
Hi,
Could u please check in debug log whether the method is call or not.because u have used reRender attribute so the page is not reloaded .So you need to add a debug in method and check in debug log
I made an additional test in my test page with an apex:param included and it still works so the issue seems to lie somewhere else:
Puja,
I haven't checked my debug log yet, but I can confirm this is because of rerender.
When I remove "rerender" the warning and action work well.
But now I have a dilemma:
Basically I have a section that show some records and my "Complete" button.
When clicking on that button, the action method marks all these actions as Complete and returns a PageRefefernce so that a full page refresh is done. The problem is that the updated actions do no display if I don't rerender the appropriate section (which I never understood since it is a full page refresh, hence a rerender should not be needed).
Now the business asks for a warning pop-up before proceeding, which I can implement thanks to your solution (using onclick="return confirm..."
But now I need to find a solutiuon where I can use onclick and rerender at the same time...
Do you have any ideas?
Thanks!
Don't just return the results of confirm(), because if you return any value from the onclick handler it will bypass the on page action where you are rerendering. Instead test for results of confirm() and only return false if it fails, don't return anything otherwise and the handlers will continue execution.
This works whether you have "rerender" or not: