How to display multiple data selected in LOV to Textbox | Oracle APEX | - oracle-apex

I have a scenario where I am stuck not getting how do I proceed with it.
Created a LOV -> which holds below values
A-A
A-B
A-C
A-D
I have set the property of LOV item -> Multiple and Separator given : ,
When I select 1st, 2nd & 4th value it should be automatically displayed in my textbox in comma separated format like following : A-A,A-B,A-D
Any solution is much appreciated !!!

Suppose you have a select list item named P92_LOV and a text field page item named P92_TEXTFIELD.
Create a dynamic action on change of P92_LOV
Add a true action
Identification > Action: Set Value
Settings > Set Type: PL/SQL Function Body
Settings > PL/SQL Function Body:
RETURN :P92_LOV;
Settings > Items to Submit: P92_LOV
Affected Elements > Selection Type: Item(s)
Affected Elements > Items(s): P92_TEXTFIELD
Try it out, whenever you select/unselect a value in the select list, the value in the checkbox will change accordingly.

Related

Use Oracle APEX LOVs to Initialize Multiple Page Items? - APEX 21.1

I understand that the default behavior of LOVs is the following:
SELECT business_desc as display_val,
business_id as return_val
FROM businesses
This attached to a select type page item P1_BUSINESS will display a list and when a list row is selected, then assign the business_id value to the page item P1_BUSINESS.
Is there a way to build a list of values to set the value of more than one page item that are not displayed? Using the below SQL:
SELECT business_desc as display_val,
business_id as return_val,
form_type,
individual_flag
FROM businesses
Where now when a user selects something from P1_BUSINESS it sets the values of that row/record as follows:
P1_BUSINESS = business_id (like it does by default)
P1_FORM_TYPE = form_type (P1_FORM_TYPE is a hidden page item)
P1_IND_FLAG = individual_flag (P1_IND_FLAG is a hidden page item)
I know I can do this with an onchange dynamic action, but just curious if can do inside the LOV or select page item (P1_BUSINESS) declaratively.
In Shared Components > List Of Values, there is an attribute "Additional Display Columns". The help text on that screen says it all Additional display columns can be defined for item types that support multiple display columns, for example the Popup LOV. For item types that do not support multiple columns, these will be ignored. If adding additional display columns ensure that the return column is included in the column list. The return column can be set to Visible No and Searchable No if you do not want it displayed to users.
Example using emp/dept sample data:
Create a list of values on table emp with return empno and display ename. Save.
Edit the LOV and click Additional Display Columns > Select Columns. Select job as additional column.
In the IG, set Visible and Searchable to "No" and Apply Changes.
On the page, create 2 page items: P1_EMPNO (type popup LOV) and P1_JOB (type Text Field)
For P1_EMPNO, pick the LOV created above as shared component > List Of Values and add JOB:P2_JOB under Settings > Additional Output. JOB is the additional column name/alias and P2_JOB is the item it should map to.
Now when you run the page, observe that P1_JOB is populated when you select a value for P1_EMPNO

How to set value for the Oracle APEX Popup LOV

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.
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;
:P2_EXTRACT_YEAR is an item hidden.
and second condition: an Exectute Javascript code
$s('extractyear',$v('P2_EXTRACT_YEAR'));
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.
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());
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

How to get the values in items without refreshing the page in apex

I have an item to enter email id, and two more items to get the values of first/last name and department of that user which we have given without refresh the page or without enter.
Item 1: ex : a...z#gmail.com (text field)
Item 2 : ex Mechanical (display only)
Item 3 : ex Abinnaya Moorthy (display only)
This should happen when we have given the email id and as soon as the cursor is out from email id the two item values should display.
I have used dynamic action but not getting exact output, please let me know.
On Item 1 make a following dynamic action:
Event: Change (I would recommend 'change', although based on your question, you might also be interested in 'Mouse Leave', although it would trigger DA even when no change in item value occurred, for example when someone just clicked on it and clicked away)
Selection Type: Item
Item: your Item 1
First true action: Execute PL/SQL Code
inserting values into your items Item 2 and Item 3, while using your Item 1 as a condition in WHERE clause
Page Items to Submit: your Item 1
Page Items to Return: your items Item 2 and Item 3
Second true action: Refresh
Selection Type: Item(s)
Item(s): your items Item1 and Item2
Let's say I have 1 field like an email field above. Then I have 50 display only fields that values are coming from (Source) SQL queries that depends on email field. How to refresh this fields without refreshing page, but also without Setting its value manually? I would only like to trigger them to perform their Source SQL query and refresh values on the page.
Setting their values by SetValue action will result in having same queries in Dynamic Action and in Source SQL Query for each field. Also for 50 fields DA would have hundreds of SQL lines and would become not maintainable.
assuming you are working on page 9, and the email field is :P9_EMAIL_ITEM, and the name fields are :P9_FNAME_ITEM and :P9_LNAME_ITEM
The email field is a text field (it doesn't matter what the source is)
The name fields should be display only, and in properties the setting "Based On" should be "Page Item Value", set the source property to type Null.
On the email text field, create a new dynamic action, set the When properties to: Event -> Change, Selection Type -> Item(s), Item(s) -> P9_EMAIL_ITEM
Under the dynamic actions you'll have a "New" event, with a "True" folder, and inside it a new action (probably "Show"). Change its action to "Set Value".
change the setting property so that "Set Type" will be "SQL statement", and write a statement with the following structure:
select FNAME_COLUMN, LNAME_COLUMN
from RELEVANT_TABLE
where EMAIL_COLUMN = :P9_EMAIL_ITEM
Under "Items to submit" select the P9_EMAIL_ITEM.
in the Affected Elements properties set Selection type -> Item(s) and Item(s) -> P9_FNAME_ITEM, P9_LNAME_ITEM
In "Execution Options" select NO for Fire on Initialization
what we did on step 5 is "refreshing" the relevant items, without refreshing the page
I just tested it out and here's what works very well:
On Item 1, create a DA on 'Loose Focus'
Create two true actions for 'Set Value', for both Item 2 and Item 3.
Select Settings > Set Type as SQL Statement.
Write query to fetch item 2 and item 3, base on item 1 (I suggest comparing lower cases of both to make it case in-sensitive.)
Items to Submit -> Item 1
And viola, it's done!

How to pass data between fields in Oracle APEX 5.1?

This is a VERY basic question. Sorry for not providing any code I have NO IDEA how to even start tackling the problem
I have lets say two fields... One is a date selector field and the other a regular text field. What I want is when I select a date (or type a date), the value comes in the second field... Just that...
I'm on APEX 5.1.4
Since you have stated that the second item is a text field, you could do this with the help of a dynamic action that sets the value of the second item when there is a change in the value of the first item ( date field).
The following would be the steps, if you are using component view:
Create Dynamic Action
When
Event : Change
Selection : Item(s)
Item : First Page Item
Condition : is not null
True Action
Action : Set Value
Fire on Page Load: No
Set Type: You can choose how you want to set the value of the second item on the page.
If you have the flexibility to change the second item to be a select list and you have a list of values that goes with a date, you could do this much simpler, with a Cascading LOV
On Second Item's - Under List of Values section
Cascading LOV Parent Item(s) : First Item
Page Items to Submit: First Item
List of Values definition: Here you can define the query.
Hope this helps.
There are a few different ways to do this, probably the easiest way is as follows.
Assume your two items are P1_ITEM1 and P1_ITEM2.
Create a dynamic action which fires on change of item P1_ITEM1.
The true action of this should be action:set value, set type:PL/SQL Expression, item::P1_ITEM2, items to submit P1_ITEM1.

Oracle Apex - Select list populates text field

I'm using Oracle Apex 4.2. I have a select list and a text field. I'm trying to create a dynamic action that should be simple enough but I'm not sure how to do it. Basically depending on what value the user selects from the list of values in the select list, the text field should then be populated. So for example:
Let's say the select list gives the user the choice to select 'Animal', 'Car', 'Person'. If the user selects 'Animal' then the text field should immediately have the value 'cat'. If the user selects 'Car' then the text field should immediately have the value 'toyota'. If the user selects 'Person# then the text field should immediately have the value 'jim' etc.
How would I make this dynamic action?
Thanks,
Stephen.
Create a New Dynamic Action with the following properties
Main Properties
Event: Change
Selection Type: Item
Item(s): [Select List]
Condition: No Condition
True Action
Action: Execute PL/SQL code
Fire When event Result is: True
PL/SQL Code:
Option 1 - use a lookup table
select LOOKUP_VALUE
into :P1_TEXT
from LOOKUP_TABLE
where original_value = :P1_SELECT_LIST;
Option 2 - Use hardcoded values
CASE upper(:P1_SELECT_LIST)
WHEN 'ANIMAL' THEN :P1_TEXT := 'cat';
WHEN 'CAR' THEN :P1_TEXT := 'toyota';
WHEN 'PERSON' THEN :P1_TEXT := 'jim';
ELSE :P1_TEXT := null;
END CASE;
Page Items to Submit: [P1_SELECT_LIST]
Page Items to Return [P1_TEXT]