Adding dynamically selected value to LOV in Oracle Apex 5 - oracle-apex

I have problem with multi-select LOVs in Apex 5.
I want to do, in programmatic way, select values in multi-select LOV.
For example I press button and some value will be selected in LOV.
Any ideas how to do this?

If you mean a Select List item that is set to allow multiple values then your button could execute this Javascript:
$('#P123_MY_MULTI_SELECT option[value="AAA"]').attr('selected',true);
$('#P123_MY_MULTI_SELECT option[value="BBB"]').attr('selected',true);
... etc.
Alternatively, you could use a dynamic action, but it wouldn't be any simpler. It would define the affected elements using a jQuery selector:
#P123_MY_MULTI_SELECT option[value="AAA"],#P123_MY_MULTI_SELECT option[value="BBB"]
... and the action would be to execute Javascript code:
$(this.affectedElements)..attr('selected',true);

I'll describe the easiest example:
Create APEX item eg. P1_MULTIPLE
Type = Select list
Allow Multi Selection = Yes
List of Values > Type = Static Values
List of Values > Static values = STATIC:Display1;Return1,Display2;Return2
Create button eg. SET_VALUES
Create dynamic action
Event = Click
Selection type = Button
Button = SET_VALUES
Create true action within DA from step 3
Action = Set Value
Set Type = JavaScript Expression
JavaScript Expression = ['Return1', 'Return2']
Selection Type = Item(s)
Item(s) = P1_MULTIPLE
Test it.
basically, if you want to change value(s) of the multi select list you need to pass array of value(s).
With pure jQuery (without APEX DA):
$("#P1_MULTIPLE").val(['Return2', 'Return1'])

Related

How to display multiple data selected in LOV to Textbox | 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.

Oracle APEX: Is it possible to disable IG select conditionally

I want to disable select on my IG when a page item P1_CONDITION meets certain criteria. I hid row action and row selector when condition is met, but if I click on any of the rows, they are still getting selected - custom delete button shows up in the toolbar. How can I disable select conditionally?
I know I can add a condition to the DA that takes care of showing or hiding the custom button but I wanted to disable select altogether. Is that possible?
You can use Javascript snippet as below to disable your grid:
var grid = apex.region("emp").call("getViews").grid;
grid.view$.grid("option", "editable", false);
grid.model.setOption("editable", false);
OR
You can also disable the column you want to disable using Execute Javascript Code action or using disable action of dynamic actions as following:
If you do not want the user to click/select the row,
Add the below code in the Execute When Page Loads section of the page.
if ($v("YOUR_ITEM") == 'YOUR_VALUE') {
$("#emp .a-GV-table tbody .a-GV-row").css('pointer-events','none');
}
Note: emp is the Static ID of the Interactive Grid.
Switch off the Select First Row property of the Interactive Grid.

Oracle Apex: Auto select if shuttle list contains only a single item

I have a shuttle list that, depending on the selection of a previous form, may have between one and seven items. Is there any way for me to automatically move the entry to the right hand pane if there is only a single selection, just for the sake of long term optimization and user friendliness?
You can add a default Value to your shuttle item
SELECT YOUR_COLUMN_ID
FROM T0000_YOUR_TABLE
WHERE FILTER_COLUMN_ID = :P_FILTER_ITEM_PREV_FORM
GROUP BY YOUR_COLUMN_ID
HAVING COUNT(*) = 1
If there are more than 1 entries for your filter item the statement will return nothing, if there is exactly 1 entry the entry will be returned and set for your shuttle item
I like sim0n's answer. But here's another that uses JavaScript (you can choose which is best for your use case).
Create a Dynamic Action. Set Name to Page loaded and Event to Page Load.
Select the Action created by default. Set Action to Execute JavaScript Code, then enter the following code in Code.
var itemId = 'P1_ITEM_NAME';
var $opts = $('#' + itemId + ' select:eq(0) > option');
if ($opts.length === 1) {
$s(itemId, $opts.val());
}
Don't forget to change the name of the item to match the one on your page.
When the page loads, the JavaScript will check to see how many options are in the select element on the left. If there's just one, it will set the value of the item using the value to the value of the single option.

Pass column classic report value to PL/SQL

I have page with Classic Report on it (type = PL/SQL Dynamic Content). What I need it's passing one column value to PL/SQL via Dynamic Action when click on another column. It's no problem to initiate click action, but I don't know how to pass equivalent of #col_name# (not :Pxxx_item_name) to PL/SQL.
Application Express 5.0.4.00.12
I'm not sure what you're trying to pass, so I'm just going to call it "item".
In your report add a custom data attribute to the column, data-item="#COL_NAME#". This would go on the image that's getting clicked. You might need to use the HTML Expression option to set this.
Create a hidden item, P1_ITEM and set Value Protected to No.
Create a Dynamic Action that fires when you click the image in the column.
Create a True action on that DA, Action = Set Value, Set Type = Javascript Expression, the JS expression is this.triggeringElement.dataset[ "item" ], Affected Element > Selection Type = Item, Item = P1_ITEM.
Create another True action on that same DA, Action = Execute PL/SQL Code, Items to Submit = P1_ITEM, and whatever code you want in the PL/SQL code section. You can reference P1_ITEM in your code with :P1_ITEM or V('P1_ITEM').
When the DA fires, it will populate the column value into P1_ITEM, then submit that to the server where it's stored in session state, then run your PL/SQL code.

Extract specific cell data from Interactive table - Oracle-APEX

I have an item P0_ITEM, I want to use a value from a particular cell in an interactive report and assign it to the item P0_ITEM, How can this be done?
Set static region ID to something like p1_ir
Define a dynamic action on click of jQuery selector
#p1_ir td
Event scope: dynamic
Execute JavaScript code
$s('P0_ITEM', $(this.triggeringElement).text());