Home > Software design >  Oracle Apex: how to link an item in a normal page to an item on a modal page
Oracle Apex: how to link an item in a normal page to an item on a modal page

Time:10-07

This is my issue: I have a text field item in a normal page (P7_PRODUCT), in this page there is a button that opens a modal page and, in the modal page there is another text field item (P7_PRODUCT). I would like that when I write a product in P7_PRODUCT, the same product appears in P8_PRODUCT. I tried with several dynamic actions, but none of them worked.

CodePudding user response:

Here's one option.

  • on page 7, there are: P7_PRODUCT text item and P7_GOTO_8 button

  • let button Submit the page

  • create branch

    • name it e.g. "Goto 8"

    • it should redirect to page 8

    • in "Link Builder", set P8_PRODUCT item to &P7_PRODUCT. (note leading ampersand and trailing dot)

      enter image description here

  • run page 7

  • enter something into the P7_PRODUCT item

  • press the button

  • modal dialog page opens and its P8_PRODUCT contains value you entered on page 7

    enter image description here

CodePudding user response:

A good blog to read is this one, by John Snyders from the apex development team. As he explains, it's not advised to branch to a modal dialog - instead you should link to it.

Here is an example based on techniques described in [this] (https://jeffkemponoracle.com/2022/02/reusable-region-as-a-modal-page/) blog.

I have 2 pages: Page 108 (normal page) and page 109 (modal page). Page 108 has a region (Region 1) with page item P108_NEW and a button called TO_MODAL. Page 109 has page item P109_NEW. When a user enters a value in P108_NEW and clicks the button, page 109 should open with the value from P108_NEW shown in P109_NEW.

The technique generates the url of the modal page and then redirects to it.

  1. Give the region on page 108 a static id: "region1". This is used if you want to create a dynamic action on close of the dialog.
  2. Create a new hidden item on page 108 (P108_URL_TO_MODAL1) to hold the value of the modal page url. Source type: Expression, source:
apex_page.get_url(
    p_page => 109,
    p_triggering_element => '$(''#region1'')'
)

Make sure to set "Used" to "Always, replacing any existing value in session state".

  1. Create a dynamic action on click of button on page 108.

  2. Add an action to the dynamic action of type pl/sql to set the value on page 109.

Action 1: Execute Server-side Code, Pl/SQL Code:

:P109_NEW := :P108_NEW;

Values to submit: P108_NEW

Action 2: Execute Javascript code:

apex.navigation.redirect("&P108_URL_TO_MODAL1.");

This should be it.

  • Related