I am working on an Oracle APEX application where I need to dynamically format a user’s input in a Date Picker item. The desired behavior is:
When the user types 20022025 (for example), the item should automatically reformat it to 20.02.2025 (i.e., DD.MM.YYYY) upon losing focus.
If a date is selected using the date picker, the value should remain unchanged.
The format mask for the Date Picker is already set to DD.MM.YYYY.
What I have tried:
//PL/SQL Dynamic Action
declare
begin
SELECT TO_CHAR(TO_DATE(:BIRTH_DATE, 'DDMMYYYY'), 'DD.MM.YYYY')
INTO :BIRTH_DATE
FROM DUAL;
end;
//PL/SQL with Conditional Formatting
declare
v_formatted_date varchar2(10);
begin
if regexp_like(:BIRTH_DATE, '^d{8}$') then
v_formatted_date := substr(:BIRTH_DATE, 1, 2) || '.' ||
substr(:BIRTH_DATE, 3, 2) || '.' ||
substr(:BIRTH_DATE, 5, 4);
end if;
:BIRTH_DATE:= v_formatted_date;
end;
//JavaScript Dynamic Action
var pid = $(this.triggeringElement).attr("id");
var value = apex.item(pid).getValue();
console.log("value:", value);
if (/^d{8}$/.test(value)) {
var formattedValue = value.substring(0, 2) + '.' +
value.substring(2, 4) + '.' +
value.substring(4);
console.log("Formatted value:", formattedValue);
apex.item(pid).setValue(formattedValue);
}
//Set Value Action with PL/SQL Function Body
declare
begin
IF REGEXP_LIKE(:BIRTH_DATE, '^d{8}$') THEN
SELECT TO_CHAR(TO_DATE(:BIRTH_DATE, 'DDMMYYYY'), 'DD.MM.YYYY')
INTO :BIRTH_DATE
FROM DUAL;
end if;
end;