Skip to main content

Restrict Input to Existing Values in a Specific Column of APEX Interactive Grid

Oracle APEX · Javascript

Validate DEPTNO in an Interactive Grid

Users can freely edit an Interactive Grid — which means they can accidentally enter a department number that doesn't exist. Here's how to catch that in real time and block the invalid entry before it reaches your database.

Step 1
Create IG region
Step 2
Hidden page items
Step 3
Page load JS
Step 4
Dynamic Action
1

Create the Interactive Grid region

Add an Interactive Grid region to your page and set its Static ID to emp. This ID is used throughout the JavaScript to reference the grid.

!

Without a static ID, APEX generates a dynamic region ID that changes between page loads — your JavaScript will break unpredictably.

2

Create two hidden page items

Add these two hidden items to your page:

P3_DEPT_UNIQUE_VAL P3_ERROR_MSG

P3_DEPT_UNIQUE_VAL stores valid department numbers from the grid. P3_ERROR_MSG carries the validation result between server and client.

3

Capture valid DEPTNO values on page load

In Execute when Page Loads, add this JavaScript. It reads all existing department numbers from the grid model and stores them as a colon-separated list.

JavaScript Execute when page loads
var deptNumber = new Set(); var model = apex.region("emp").widget().interactiveGrid("getViews","grid").model; model.forEach(function(record) { var deptno = record[model.getFieldKey("DEPTNO")]; deptNumber.add(deptno); }); var uniqueDeptno = Array.from(deptNumber); $s("P3_DEPT_UNIQUE_VAL", uniqueDeptno.join(":"));
4

Create a Dynamic Action on DEPTNO column change

Create a Dynamic Action that fires on the Change event of the DEPTNO column. Add three actions in this exact order:

Action 1 — Check the value (PL/SQL)

Submits the entered DEPTNO to the server and sets an error message if it's not in the valid list.

PL/SQL Submit: DEPTNO, P3_DEPT_UNIQUE_VAL  |  Return: P3_ERROR_MSG
IF INSTR(:P3_DEPT_UNIQUE_VAL,:DEPTNO,1)= 0 THEN :P3_ERROR_MSG := 'The Department Number must match one of the existing departments. Assigning a new Department Number is not allowed'; END IF;
Action 2 — Show dialog and clear value (JavaScript)

If an error message was returned, shows a confirmation dialog. Either way, the invalid value is cleared from the cell.

JavaScript
if ($v('P3_ERROR_MSG') != '') { apex.message.confirm($v('P3_ERROR_MSG'), function(okPressed) { if (okPressed) { var grid = apex.region("emp").widget().interactiveGrid("getViews", "grid"); var model = grid.model; var record = grid.getSelectedRecords()[0]; if (record) { model.setValue(record, 'DEPTNO',''); } } else { var grid = apex.region("emp").widget().interactiveGrid("getViews", "grid"); var model = grid.model; var record = grid.getSelectedRecords()[0]; if (record) { model.setValue(record, 'DEPTNO',''); } } }); }
!

Both OK and Cancel clear the field — once flagged as invalid, there's no valid path to keep the value in the cell.

Action 3 — Reset the error message (PL/SQL)

Clears P3_ERROR_MSG so the next change starts fresh.

PL/SQL Return: P3_ERROR_MSG
:P3_ERROR_MSG := null;

With these three actions in place, any DEPTNO that doesn't exist in the grid is caught immediately, the user is informed, and the field is cleared — keeping your data clean without any extra database constraints or plug-ins.

Comments

Popular posts from this blog

Generate Custom PDFs in Oracle APEX with jsPDF

Generate Custom PDFs in Oracle APEX with jsPDF A complete step-by-step guide to building a client-side PDF generator with profile image embedding and PL/SQL database persistence. 📄 Step-by-step guide Oracle APEX jsPDF Dynamic Actions PL/SQL JavaScript "Picture this: your Oracle APEX application is polished, your users love it — but when they ask for a downloadable report with a profile picture and custom styling, you realize vanilla APEX isn't built for that out of the box. What if a single JavaScript library and one Dynamic Action could change everything?" Welcome to the world of jsPDF inside Oracle APEX . In this tutorial, we wire up a PDF generator that captures a user's name, email, phone number, and profile picture — renders them into a beautiful PDF layout — and saves everything to Oracle, all in one button click. ⓘ What you'll build: A dynamic PDF generat...

APEX Custom Auth Settings, Decoded!

Oracle APEX Security PL/SQL APEX Custom Auth Settings, Decoded Why I Build this I was building an internal APEX app — strictly for people on our corporate network. The default authentication worked, but it had a few things that kept bothering me. Anyone with valid credentials could log in from anywhere. Sessions expired with a useless error page. There was no audit trail — no way to know who logged in, when, or from where. And passwords were stored in plain text, which I just couldn't leave alone. So I did what any developer does — I built it myself. Custom authentication, from scratch, in PL/SQL. Turned out to be one of the best learning experiences I've had with APEX. Here's exactly how I did it. Img 1 : Head to Shared Components → Authentication Schemes → Create, choose Custom as the Scheme Type, and plug in your function and procedure names. Quick note before we get into the code — the s...

Record, Preview, Save — Video Recording in Oracle APEX

Oracle APEX · Video Recording Record Video Directly in Oracle APEX ๐ŸŽฌ Have you ever wished your users could say it instead of type it? In many modern applications, we've seen the ability to record a short video clip directly in the browser — no file uploads, no external tools. Just hit record, watch it back, and decide — save it or try again. Today, we're bringing that same experience into Oracle APEX: record, pause/resume, preview, save to DB, or retry. Let's build it. 1 Step 1 : Start by creating a Static Content Region on your APEX page. This will act as the container for our entire video recorder UI.Paste the provided HTML code into the region source. This gives you two video panels — one for the live camera preview and one for the recorded playback — along with your action buttons: Start, Pause, Resume, Stop, Save, and Retry. Copy <!-- Recorder UI --> < div id= "recorderUI...