I have a page with a Yes/No Page item (similar to Select list with options as Yes/No). I have a simple requirement to confirm with the user upon selection(means change) of that page item.
For that I created a dynamic action which will fire on change of that Page item. In that i added a true action of type javascript.
In that i confirm with user on their selection. Problem is for example, if value is No, and user selects Yes, and a confirm pop-up appears. when user clicks on 'Cancel' in Confirm box, PI value still becomes Yes (new selected value).
To avoid that, in my code i change the value back to old value when Cancel is clicked. When that code executes, it fires the Dynamic Action again and that happens recursively due to change event.
if ($v('P2_APPROVE')=='Y'){
// apex.confirm('Please Confirm that you want to approve?', 'Approve');
var ans=confirm('Please Confirm that you want to approve?');
if (ans){
apex.submit('Approve');
}
else{
$s('P2_APPROVE','N');// PC: This fires DA again and it goes to below else
}
}
else {
// apex.confirm('Please Confirm that you want to Reject?', 'Reject');
var ans2=confirm('Please Confirm that you want to Reject?')
if (ans2){
apex.submit('Reject');
}
else{
$s('P2_APPROVE','Y');// PC: This fires this DA again and goes to if part
}
}
Q: How to simply implement this requirement to confirm user's selection and take appropriate action? Is there anything wrong i am doing. I thought clicking on Cancel will cancel the change.
Q: Does apex.confirm() also returns anything so that we can reset the value to old if user clicks on Cancel in the confirm box. As this also retains new selection even if user clicks on Cancel.