Oracle Apex: Using Javascript to perform item validation on a DA

 Requirement

You have a dynamic action which executes some javascript. But you would like to add some validation to check for blank items. (this example checks two items). If either of the items is blank, display an error on the item and do no continue with the next action.


Solution.

Before executing your main Javascript action. (Or in fact any DA action), add a Javascript action.




Code:

// First clear the errors
apex.message.clearErrors();
if($v('P42_SUBJECT') === "") {
// Now show new errors
apex.message.showErrors([
    {
        type:       "error",
        location:   [ "page", "inline" ],
        pageItem:   "P42_SUBJECT",
        message:    "Subject is required!",
        unsafe:     false
    }
]); 
//To stop the further actions from firing
apex.da.cancelEvent.call(this);
}  


if($v('P42_RECIPIENT') === "") {
// Now show new errors
apex.message.showErrors([
    {
        type:       "error",
        location:   [ "page", "inline" ],
        pageItem:   "P42_RECIPIENT",
        message:    "Recipient is required!",
        unsafe:     false
    }
]); 
//To stop the further actions from firing
apex.da.cancelEvent.call(this);
}  

Explanation

Check the value of P42_SUBJECT, if null display an error and stop.

Continue to P42_RECIPIENT, if nul..

etc.

Result


Acknowledgement

Comments