0
votes

I'm looking for a way to set a value in Popup Lov item. I'm using Oracle Apex and I'm trying to set value of Popup LOV with dynamic action. I would like to set a year after to have choosen a date from a date picker and refresh the year in a popup LOV item.
On Apex I've create a popup Lov item called P2_YEAR and a date picker called P2_DATE. On P2_date, I've created a dynamic action (Client-side Condition item not null - P2_YEAR) with two true condition. enter image description here

First condition: Execute a Pl\sql code to extract the year:

declare
   year number;
   tmp date;
begin
   tmp:=:P2_DATE;

   SELECT EXTRACT (YEAR  FROM  tmp) YEAR
   into year
   FROM DUAL;
   :P2_EXTRACT_YEAR := YEAR;
      return; 
end;

enter image description here

:P2_EXTRACT_YEAR is an item hidden.

and second condition: an Exectute Javascript code

$s('extractyear',$v('P2_EXTRACT_YEAR'));

enter image description here

On P2_Year I added in Advanced - CSS classes the class name extractyear.

What I would obtain is to show the year in the popup item box and if I push on arrow to show only the year previously extract from the date.

This configuration doesn't work.

2
Have you considered getting this functionality with a cascading list of values ?Koen Lostrie
Yes, it is considered, but the day field and the year field must be independent. In part, I managed to solve it by changing the second condition``` apex.item("P2_YEAR").setValue(apex.item("P2_EXTRACT_YEAR").getValue());``` Now It works,but I get a session state violation error when I press the button to pass the chosen values to the next page.Scripta14

2 Answers

1
votes

There are 2 portions to your answer: 1) generate the list of values for P2_YEAR. 2) set the value for P2_YEAR

1) This can be achieved using a cascading LOV on item P2_YEAR. Use source

WITH YEARS (yr) AS
(
  SELECT TO_CHAR(TO_DATE(:P2_DATE,'DD-MON-YYYY'),'YYYY')  + LEVEL - 2   FROM DUAL
    CONNECT BY LEVEL < 3
)
SELECT yr as r, yr as d FROM years

and set parent item P2_DATE. My item P2_DATE has format mask DD-MON-YYYY

Now if the P2_DATE changes, the options in P2_YEAR will change accordingly.

2) do this using a dynamic action on change of P2_DATE

first action: set value, pl/sql expression, EXTRACT( YEAR FROM TO_DATE(:P2_DATE,'DD-MON-YYYY')) on item P2_EXTRACTYEAR

2nd action: execute javascript code, affected element Item P2_YEAR

apex.item("P2_DATE").setValue(apex.item( "P2_EXTRACTYEAR" ).getValue(),apex.item( "P2_EXTRACTYEAR" ).getValue()); 
0
votes

Right-click on the :P2_DATE and select Create Dynamic Action. Set the following properties:

Event: Change
Selection Type: Items(s)
Item: P2_DATE

Client Side Condition

 Type: Item is not null
 Item(s): P2_DATE

Right-click the dynamic action and select either Create TRUE Action. Set the following properties:

 Action: Set Value
 Set Type: PL/SQL expression 
 PL/SQL expression : TO_CHAR(TO_DATE(:P2_DATE,'DD-MON-YYYY'),'YYYY')
 Items to Submit: P2_DATE
 Affected Elements > Selection Type: Item(s)
 Affected Elements > Item(s): P2_YEAR

FALSE Action

 Action : Set value
 Set Type: PL/SQL expression 
 PL/SQL expression : :P2_YEAR = ''
 Items to Submit: P2_YEAR
 Affected Elements > Selection Type: Item(s)
 Affected Elements > Item(s): P2_YEAR