I have a custom tabular form based on a collection and I'm interested in being able to validate the value entered by a user in any given row/column combination. Conceptually, it is basically a grid-format time sheet, where each row represents a task, and each column represents a day of the week.
| Task Name | 03 / 24 Mon
| 03 / 25 Tues
| 03 / 26 Wed | 03 / 27 Thurs | 03 / 28 Fri | 03 / 29 Sat
| 03 / 30 Sun
| 03 / 31 Mon
| 04 / 01 Tues
| 04 / 02 Wed
| 04 / 03 Thurs
| 04 / 04 Fri
| 04 / 05 Sat
| 04 / 06 Sun
| Task ID |
|---|
| Task A | 1 | 3 | | 4 | | | | 1 | 6 | | 3 | | | | 12345 |
| Task B | 4 | 3 | 6 | 1 | 4 | | | 2 | 1 | 2 | 3 | 5 | | | 67890 |
| Task C | 2 | 2 | | 1 | | | | | | 7 | 2 | 2 | | | 45789 |
| Task D | 1 | | 2 | 3 | 4 | | | 5 | 1 | | | | | | 12389 |
The user can enter hours worked for any given task, for any given day of the week. So whenever the user inputs some hours, the form needs to validate whether that task still has a valid GL code for the current time period. I started to go down the path of Javascript / AJAX for validating prior to submitting the form, but got stuck on how to reference values in other cells on the same row. For example, the user enters some hours in tabular form cell f03_0010, the javascript needs to look up the "task id" found in f18_0010 (Task ID is actually a hidden column but always in f18_xxxx cell). It should then pass the value of f18_0010 to checkWBS function (see below) which calls an application process using PL/SQL to verify whether the task id is still valid.
function checkWBS(pITEM) {
var get = new htmldb_Get(null, html_GetElement('pFlowId').value, 'APPLICATION_PROCESS=VALIDATE_TASK_CODE',0);
get.addParam('x01',pITEM);
var gReturn = get.get();
return gReturn;
}
Having client-side validation would be nice, but alternatively, a page process which executes On Submit will also work. I understand that I could achieve this by looping through each row using the syntax below, but since the columns can span a 2-week period (14 cells) what's the best way to go through each column without having to code for each day? Are there any built-in APEX functions to make this easier?
BEGIN
FOR i IN 1..apex_application.g_f02.count LOOP
IF apex_application.g_f03.count > 0 THEN
v_tot_hours := v_tot_hours + TO_NUMBER(NVL(RTRIM(apex_application.g_f03(i)),'0'));
END IF;
/* keep adding all 14 days to v_tot_hours */
IF apex_application.g_f016.count > 0 THEN
v_tot_hours := v_tot_hours + TO_NUMBER(NVL(RTRIM(apex_application.g_f016(i)),'0'));
END IF;
/* now validate if there are hours entered for the task during any day */
IF v_tot_hours > 0 THEN
-- do something here
END IF;
END LOOP;
END;
Hope this makes sense. Thanks for any input!
Oracle APEX 4.2