SmashingCode
SmashingCode

Reputation: 21

Oracle apex form validation before Dynamic Action

I'm calling a Dynamic Action from a button in order to save my form data via PL/SQL Code using a stored procedure. I prefer using the stored procedure as it gives more control as to how I am saving the data from the form.

I am facing difficulties in getting the normal validation on the column items to warn the user of failed validations to fire before clicking the button that is associated with the Dynamic Action click event. On a normal submit page button the validation works, but I need the flexibility of using a stored procedure and I need the validation. Please can someone advise me on what I might be missing here. Regards from SmashingCode.

Upvotes: 2

Views: 7251

Answers (1)

Akil_Ramesh
Akil_Ramesh

Reputation: 431

Follow the below steps to perform validation before performing DML via Dynamic action:

  1. Create a Page Item (in this example: P1_ERROR_FLAG)
  2. Create a dynamic action (in your case: On Click of a button)
  3. Create a True action. Type: Execute Server Side Code
    Write your PL/SQL block (or) Call a Procedure that sets the value to the page item P1_ERROR_FLAG
    Example:
    BEGIN
      IF :P1_NAME IS NULL THEN
        :P1_ERROR_FLAG := 'Y';
      ELSE
        :P1_ERROR_FLAG := 'N';
      END IF;
    END;
    
  4. Submit the Items P1_NAME, P1_ERROR_FLAG and Return the Item P1_ERROR_FLAG
  5. Create a True action. Type: Execute JavaScript Code
    Example:
    // First clear the errors
    apex.message.clearErrors();
    
    var errorFlag= $v('P1_ERROR_FLAG');
    
    if(errorFlag == 'Y') {
    // Now show new errors
    apex.message.showErrors([
        {
            type:       "error",
            location:   [ "page", "inline" ],
            pageItem:   "P1_NAME",
            message:    "Name is required!",
            unsafe:     false
        }
    ]); 
    //To stop the further actions from firing
    apex.da.cancelEvent.call(this);
    }  
    
  6. Create another True action Type: Execute Server Side Code and write your DML code.

Reference: https://docs.oracle.com/database/apex-5.1/AEAPI/apex-message-namespace.htm#GUID-230C2CC1-B721-4037-8384-7B5369F35A2F

Upvotes: 3

Related Questions