Ollie
Ollie

Reputation: 17538

APEX: Call JavaScript function after validation but before processing

I have been tasked with re-creating an old PL/SQL Web Toolkit front end in Application Express (Apex).

I would like to display a popup after the page is submitted and after computations and validations.

The page can be submitted by clicking a button OR by hitting enter.

I have googled and got a modal popup working (called by javascript) but I can't seem to call it at the right point. I can call it on submit (before the validations etc.) but not after the validations.

I have tried creating a branch to URL at the correct processing point and then have the URL set to:

javascript:openForm();

But then I get a page will not display error.

Can anyone out there explain how I could do this?

Apex Version: 4.0.2 Oracle 10g

Upvotes: 2

Views: 9100

Answers (1)

Tom
Tom

Reputation: 7028

I suppose what you want to do is to perform the validations, have values submitted to session state, but not execute further processes. However, when you submit the page it is sent to the server; and everything you see in the page processing region will sequentially fire. There is no way to halfway through the processes call a javascript function, since basically you are not on the clientside anymore.

What you can do is to create a branch after your validations to the same page. Redirect to it but provide a REQUEST value, for example OPENFORM.

Create a dynamic action, firing on page load, with a true action that executes javascript and opens up your modal page. Then set the condition on your dynamic action to Request = Expression 1, providing the request value to Expression 1 (OPENFORM). (Note that this is the Conditions region, and not the 'Condition' field of the 'When' region)

This should cause the page to be submitted, validated, then re-loaded but with a request value, and the dynamic action firing, opening your modal page.

Just a point of interest: If you have actual processes on this page though, then be careful with the Enter key. Buttons by default submit to session with the request value set to their name, and thus making it possible to conditionally execute processes or branches. The enter key does not submit with a request value set i believe. So if your branch is conditional, the enter key might simply skip over it.

Upvotes: 2

Related Questions