IntroductionIt's often a good idea to have validation on your forms in APEX, especially when you have business rules that govern how data can be entered. On a recent system enhancement we wanted to add a 'target bonus' flag to a page, but only allow it to be set to 'Yes' if the 'rebate level' was not set to 'None'.
This is simple enough to do..
Create a Page Validation, with a validation type of 'PL/SQL', 'Function Returning Boolean', then enter code as follows:-
IF :P4_TARGET_BONUS = 'Yes' AND :P4_REBATE_LEVEL = 'None' THEN
But it turns out that it's not quite what the customer wanted. There may be instances were it's OK to break these rules, so in that case can we just warn the user by showing a pop-up confirmation box instead.
Confirmation boxes are a UI thing which needs to happen before the page is submitted, so this sounds like a job for a dynamic action.
Using Dynamic Actions For ValidationI deleted the page validation (above) and set about using jQuery and a Dynamic Action to perform the same field comparison, but this time at the browser level.
|Adding a Confirm action for soft validation.|
1. Create a dynamic action against your submit button and set the following details in the When section.
Selection Type: Button
Value: ($v('P4_TARGET_BONUS') == 'Yes' && $v('P4_REBATE_LEVEL') == 'None');
2. Next add a True action for when validation fails..
Action: Confirm Fire When Event Result is: True Text: Target Bonus is not allowed while Rebate Level is 'None', continue?
3. Add another True action which will be used if OK is clicked on the confirm action..
Action: Submit Page Fire When Event Result is: True Request/Button Name: UPDATE
4. Finally add a False Action to perform a simple submit if validation passes..
Action: Submit Page
Fire When Event Result is: True
Request/Button Name: UPDATE