Apex_Item_Text添加/移除行:初始空文本框及输入处理问询
Got it, let's break down how to make this work in your APEX app. You're using apex_item.text(null) to render empty text boxes in your report, and need to trigger row add/remove actions when users type 'Delete' or 'Add' into those boxes. Here's a step-by-step solution that covers both frontend and backend logic:
First, modify your existing SQL to give each text input a unique ID tied to the row's GUID. This helps us target the right row when the user enters an action:
select distinct a.GUID, a.CREATED_BY, a.created_date, apex_item.text( p_idx => null, p_value => null, p_size => 10, p_maxlength => 10, p_attributes => 'class="action-input" id="action-input-'||a.GUID||'"' ) as Action from NON_DYNAMIC_USER_GROUP_MEMBERS a join NON_DYNAMIC_USER_GROUPS b on a.DYNAMIC_GROUP_ID = b.DYNAMIC_GROUP_ID where instr(','||b.DYNAMIC_GROUP_ID||',' , ','||:P153_ID_HIDDEN||',') > 0;
I added a class="action-input" for easy selection and an id that includes the row's GUID—this will let us grab the specific row we need to modify later.
Next, create a dynamic action to listen for user input in those text boxes and trigger the right action:
- Go to your page's Dynamic Actions section and click Create
- Name it something like "Process Action Input"
- Event: Choose Key Release (or Blur if you want to trigger when the user clicks away from the input)
- Selection Type: jQuery Selector, enter
.action-inputto target all our action text boxes - Condition: JavaScript Expression, enter this to check for valid inputs:
($(this.triggeringElement).val().trim().toLowerCase() === 'delete' || $(this.triggeringElement).val().trim().toLowerCase() === 'add') - Now add a True Action: Execute JavaScript Code
Paste this code (adjust the report static ID to match yours):
Make sure to replaceconst inputEl = $(this.triggeringElement); const action = inputEl.val().trim().toLowerCase(); const rowGuid = inputEl.attr('id').split('-').pop(); // Extract GUID from the input's ID // Validate input again (extra safety) if (!['delete', 'add'].includes(action)) { apex.message.showErrors([{ type: 'warning', location: 'inline', pageItem: inputEl.attr('id'), message: 'Only "Delete" or "Add" are allowed', unsafe: false }]); inputEl.val(''); return; } // Call backend process via APEX AJAX apex.server.process('PROCESS_ROW_ACTION', { x01: action, x02: rowGuid, x03: apex.item('P153_ID_HIDDEN').getValue() }, { success: () => { // Refresh the report to show updated rows apex.region('YOUR_REPORT_STATIC_ID').refresh(); // Clear the input box inputEl.val(''); apex.message.showPageSuccess('Action completed successfully!'); }, error: (xhr) => { apex.message.showErrors([{ type: 'error', location: 'page', message: `Failed to process action: ${xhr.responseText}`, unsafe: false }]); } });YOUR_REPORT_STATIC_IDwith the actual static ID of your report (find this in the report's Attributes tab).
Now we need a PL/SQL process to perform the actual database operations:
- Go to Shared Components > Processes > Create
- Name it
PROCESS_ROW_ACTION - Type: PL/SQL
- Process Text:
Important note: TheDECLARE l_action VARCHAR2(10) := apex_application.g_x01; l_row_guid VARCHAR2(100) := apex_application.g_x02; l_group_id NUMBER := apex_application.g_x03; BEGIN IF l_action = 'delete' THEN -- Delete the specific row from the members table DELETE FROM NON_DYNAMIC_USER_GROUP_MEMBERS WHERE GUID = l_row_guid AND DYNAMIC_GROUP_ID IN ( SELECT DYNAMIC_GROUP_ID FROM NON_DYNAMIC_USER_GROUPS WHERE instr(','||DYNAMIC_GROUP_ID||',' , ','||l_group_id||',') > 0 ); ELSIF l_action = 'add' THEN -- Add a new row (adjust this logic to match your actual data needs!) -- Example: Add a new member using the current app user and current date INSERT INTO NON_DYNAMIC_USER_GROUP_MEMBERS ( GUID, CREATED_BY, CREATED_DATE, DYNAMIC_GROUP_ID ) SELECT SYS_GUID(), -- Generate a new unique GUID :APP_USER, -- Current logged-in user SYSDATE, -- Current date/time DYNAMIC_GROUP_ID FROM NON_DYNAMIC_USER_GROUPS WHERE instr(','||DYNAMIC_GROUP_ID||',' , ','||l_group_id||',') > 0; END IF; COMMIT; EXCEPTION WHEN OTHERS THEN RAISE_APPLICATION_ERROR(-20001, 'Error: ' || SQLERRM); END;addlogic here is a basic example. If you need to add a specific user (not just the current one), you'll need to adjust the INSERT statement to pull the correct user data—maybe add another input to capture the user ID, or reference a different table.
- Save all your changes and run the page
- Type "Delete" into a text box: the row should disappear after the report refreshes
- Type "Add": a new row should appear (based on your INSERT logic)
- If something breaks, check the browser console for JS errors and the APEX debug log for PL/SQL issues
内容的提问来源于stack exchange,提问作者Abinnaya

