1. Overview

This document talks about Focus on first editable page item on page load. This has been achieved using SQL and JavaScript.

2. Technologies and Tools Used

The following technologies has been used to achieve the expected output.

  • SQL/PLSQL
  • Oracle Apex
  • JavaScript

3. Use Case

Assume that we are having the requirement to focus on first editable page item on all pages in the application.

This document explains how to achieve this requirement.

4. Architecture 

Following steps explains in detail,

Step 1:

We needs to create region procedure to get first region and in region we fetch first editable page item below is code.

create or replace PROCEDURE sp_fnd_page_itm (

P_app_id NUMBER,

P_page_id NUMBER,

o_page OUT VARCHAR2

)

IS

CURSOR c_region IS

SELECT REGION_ID, r.REGION_NAME

FROM APEX_APPLICATION_PAGE_REGIONS r

WHERE r.page_id = P_page_id

AND r.APPLICATION_ID = P_app_id

AND NVL(r.CONDITION_TYPE, ‘Y’) <> ‘Never’

AND REGION_NAME NOT IN (‘Breadcrumb’) AND TEMPLATE NOT IN (‘Inline Dialog’)

ORDER BY r.display_sequence fetch first 1 row only;

CURSOR c_item (P_REGION_ID NUMBER) IS

SELECT i.ITEM_NAME

FROM apex_application_page_items i

WHERE i.REGION_ID = P_REGION_ID

AND i.page_id = P_page_id

AND i.APPLICATION_ID = P_app_id

AND i.DISPLAY_AS NOT IN (‘Hidden’, ‘Display Only’, ‘Radio Group’)

AND NVL(LOWER(HTML_FORM_ELEMENT_ATTRIBUTES), ‘y’) NOT LIKE (‘%readonly=”true”%’)

AND NVL(READ_ONLY_CONDITION_TYPE, ‘Y’) <> ‘Always’

AND NVL(i.CONDITION_TYPE, ‘Y’) <> ‘Never’

ORDER BY i.display_sequence fetch first 1 row only;

— Declare a variable to store concatenated item names

lv_result VARCHAR2(4000);

BEGIN

lv_result := ”; — Initialize the result string

FOR i IN c_region

LOOP

FOR j IN c_item(i.REGION_ID)

LOOP

— Concatenate item names

lv_result := lv_result || j.ITEM_NAME || ‘, ‘;

END LOOP;

END LOOP;

— Remove the trailing comma and space from the result string

IF LENGTH(lv_result) > 0 THEN

lv_result := RTRIM(lv_result, ‘, ‘);

END IF;

— Assign the result to the output parameter

o_page := lv_result;

EXCEPTION

WHEN OTHERS THEN

o_page := ‘error’;

END sp_fnd_page_itm;

 

Step 2: After that create hidden page item in global page(Zero Page) with name of P0_FOCUS to store the first page item .

Step 3: Then create  Page Load Dynamic action on global page with name of Get page item. And in action select execute server side code and put the below code.

BEGIN

DECLARE

l_page_name VARCHAR2(4000);

BEGIN

:P0_FOCUS := null;

sp_fnd_page_itm(

P_app_id => :APP_ID,

P_page_id => :APP_PAGE_ID,

o_page => l_page_name

);

:P0_FOCUS := l_page_name;

EXCEPTION

WHEN OTHERS THEN

:P0_FOCUS := ‘error’;

END;

END;

Step 4: Create another true action in same dynamic action and select action type as execute JavaScript code. Use below is the JavaScript.

 

$(document).ready(function(){

var itemValue = apex.item(“P0_FOCUS”).getValue();

$(“[name=” + itemValue + “]”).focus();

console.log(‘item value ‘ + itemValue);

});

Step 5:

Create Region with Email Page item and button to send the Compared report on mail as below screenshot.

5. Screen Shot

Output:

Using above steps we can Focus on first editable page item on page load.

Recommended Posts

Start typing and press Enter to search