Oracle APEX - how to show an item on page load based on the value of another item - oracle-apex-5.1

I have an item on the page which I want to show/hide on page load based on the value of another item. If item2 is Yes, then show item1, or if item2 is No, then hide item1.
I know how to do that using dynamic action and javascript but I want to avoid using javascript. Is there a way to use APEX built-in functionality to do that? I know I can use Show action to hide an item, but I only need to show it if item2 is Yes. The APEX Show action does not have a condition
Also have the same issue with On Change event:
var result = document.getElementById("result");
var status = document.getElementById("status");
if (status.options[status.selectedIndex].text == "Completed") {
var r = confirm("Are you sure you want to set the status to Completed?");
if (r == true) {
apex.submit({request:'STATUS_CHANGE'})
}
} else {
result.value = "";
$x("P2_THE_DATE").value = "";
apex.submit({request:'STATUS_CHANGE'})
}
//set a value of a hidden field for status
apex.item("P2_STATUS").setValue(status.options[status.selectedIndex].text);
Is there a better, more efficient way to do this?

ITEM2 must get its value on load somehow, right? So, use the same code (that populates ITEM2) as a condition for ITEM1 and check whether its value is "Yes" (and display it) or "No" (so don't).
I prefer using a function that returns a Boolean to do so; something like
declare
l_item2 varcahr2(10);
begin
-- this is supposed to look like source for ITEM2
select ...
into l_item2
from ...
where ...;
return l_item2 = 'Yes';
end;

Isn't that a perfect use case to incorporate js - to have a dynamic behavior on a web page. Why would you want to avoid it? I'm just curious.
Anyway, you could however achieve similar behavior, provided the item2 is a Select List or Radio Group.
Set the 'Page Action on Selection' to Submit
Set the source used to 'Only when current values is NULL' - so the value gets stored in the session even after submitting the page.
Have the conditional display for item1 set as "ITEM is NOT NULL" and choose ITEM2 as the item.
If you follow these steps, the ITEM1 would show up after the selection of ITEM2.

Related

Oracle APEX - I need help to setup dynamic search filter on IG report

I have an IG region where I disabled the toolbar and created my custom search item.
I want user to be able to type the first three characters of a name on the search item (named P8_SEARCH) and the IG report will only show the name(s) that starts with those 3 characters.
This should happen without clicking any button. The IG report query is shown below:
select member_id, first_name, last_name , address, dob, home_phone, cell_phone,
email_address from member_profile where first_name like '%'||:P8_SEARCH||'%';
I also created dynamic action with key release event and True action Execute JavaScript Code shown below:
var keyPressCount=0;
$("#P8_SEARCH").on("keypress", () => {
if (keyPressCount < 2) {
keyPressCount++;
} else {
$s("P8_SEARCH", apex.item( "P8_SEARCH" ).getValue());
}
})
How can I achieve this without submitting the page? I will appreciate any suggestion. Example:
Set an static_id for your IG region, in the dynamic action add apex.region("yourStaticId").refresh();to your JS code, this will refresh only the region.
something like this:
var keyPressCount=0;
$("#P8_SEARCH").on("keypress", () => {
if (keyPressCount < 2) {
keyPressCount++;
} else {
$s("P8_SEARCH", apex.item( "P8_SEARCH" ).getValue());
apex.region("yourStaticId").refresh();
}
})
If the search items are stored in an associated table, my idea is that you could associate a PL/SQL expression to execute using a Process. This process could be executed on a custom action.
Another idea is that you associate the dynamic action with a hidden button press, and make the JavaScript code click on the button. Then, you can 'simulate' the existence of a trigger for your dynamic action with key release event
What do you think?

Cannot clear one of the page items via dynamic action

I have a couple of text fields that are filled from the database when the value of a select list changed.
I added another action to the list change dynamic action to execute PL/SQL code:
IF :P2_SELECT_LIST1 LIKE '%ABC%' AND :P2_NAME = 'WWW' THEN
:P2_NAME = NULL;
END IF;
Nothing happend on the page when I change the value of the select list, but the session value of P2_NAME gets cleared.
I also tried:
IF :P2_SELECT_LIST1 LIKE '%ABC%' AND :P2_NAME = 'WWW' THEN
:P2_NAME = '';
END IF;
But gotten the same result
In this dynamic action there are two fields next to your pl/sql code:
Items to submit: list the items here that you use in your pl/sql to get the values from session (if necessary, the values are usually already in session).
Items to return: list the items here that you need to refresh the value on the HTML page after some change in your pl/sql
I think this solves the problem.

Getting prevalue id from umbraco dropdown list

I'm currently trying to implement AJAX results filtering on a certain page.
I created the dropdowns(on the client side), so that they have the umbraco prevalue id as their value.
I will then send this id to the server, rather than the text value. Then I loop through my content to find items with this same id.
The problem, however, is that I can't figure out how to get the value id from the property. Everything either returns the text value, or just a 0 value.
This is being performed in an ApiController.
These are all of the options I've tried:
IPublishedContent root = Umbraco.TypedContentAtRoot().First();
var downloads = root.Children.Where(q => q.Name == "Downloads").SingleOrDefault();
foreach (var item in downloads.Children)
{
var test = item.GetPropertyValue<int>("classification");
var testing = item.GetProperty("classification");
var testVal = testing.DataValue;
var testValToo = testing.GetValue<int>();
var testThree = testing.Value;
}
These are the results in order:
- 0
- IPublishedProperty
- "textValue"
- 0
- "textValue"
Is it possible to get the selected value id from a dropdownlist property? Or is string matching my only option to compare values?
EDIT:
Nevermind, found the solution. Posting the answer here, in case someone else needs it.
I was using the data type dropdownlist. I should have been using dropdownlist:publishing keys.
dropdownlist only ever returns a value. dropdownlist:publishing keys, however, returns the prevalue id, rather than the text value.
Source
Something like this perhaps.
library.GetPreValueAsString(node.GetProperty<int>("sectionType")).ToLower()

CRM 2013 Dynamic OptionSet issue

I am using CRM 2013 On premise, and in it there is an attribute which has an option set (not global) having text and value as "Dummy Entry" "0". Default Value is unassigned.
My code is to add options in this option set with some business logic. So I can add new options in it via Javascript.
When I am adding Options in it via Javascript, it is not allowing me to change the value lets say
Option1 val1
Option2 val1 is added then it wont allow me to select these values and every-time selecting them will revert to default entry "--" and nothing will change.
But lets say I add
"Option1" "0"
"Option2" "0"
as text and values, they are shown finely and selecting any of them changes the text to "Dummy Entry".
Basically somehow if the value exists in the list of Options (which are static and not added via JS), it is accepting and selecting it and showing text from it.
If the value is not found in the static option list, it doesnt select anything and show default "--"
I hope I am clear, please let me know in case of any confusion. The following snippet is working in CRM 2011 while not working in CRM 2013.
// testing function
populateBundleLists: function () {
var bundleListControl = Xrm.Page.getControl("XXX_bundlelist");
var bundleOptions = bundleListControl.getAttribute().getOptions();
var bundleOption = bundleOptions[0];
bundleListControl.clearOptions();
// add some arbitrary values to control
for (var i = 1; i <= 7; i++) {
bundleOption.value = i;
bundleOption.text = 'Dummy bundle ' + i.toString();
bundleListControl.addOption(bundleOption, i - 1);
}
},
CRM stores OptionSets in the entity configuration and will need to know about all of the possible values. You cannot add new options using JS b/c the system will not be able to resolve your new value when someone queries using a different mechanism (Fetch XML, Advanced Find, filtered view, etc).

How to set default selected options in magento product detail page

I have requirement in which i am getting product ID from external Application with product super_attribute options like color,size. I am getting all those and i can do the add to cart option.
But here my actual requirement is to select the requested options by customer and redirect them to product detail page in magento so that here they can still enter optional text to print. So i need to set the requested options in detail page and redirect them to product detail page instead of adding it to cart. They will enter more details and then they will do addtocart manually.
How can i set the selected options while loading itself.
Please help me.
Thankfully this is already built in to most themes. You need to know the ID of both attributes and values from the Simple product that is included in the Configurable product. I've only seen it work with Configurable types so that might be a limitation.
For each attribute make a key=value pair
Combine the attributes as a query string, eg. "123=345&678=890"
Append the string as a hash fragment (not as a query).
This is an example from the official demo, note that the first option needs to be selected for the second to work so it has two key/value pairs.
http://demo.magentocommerce.com/zolof-the-rock-and-roll-destroyer-lol-cat-t-shirt-126.html#525=99&272=22
Rough Magento2 example add the below for pre-selecting the custom options by name=value in:
/www/mysite/app/design/frontend/mycompany/mytheme/Magento_Catalog/templates/product/view/options.phtml
The below code looks at the label of the option and the text value of the select. And depends on your theme structure. Example below for Luma.
It expects the following format in the url
product.html?SelectLabel=OptionValue&SelectLabel=OptionValue
This does not account for multi language etc.. you could easily adapt it to instead look for the select id and option id which would be more accurate replacing
$(label).parents().eq(1).find('select option:contains('+arr[k]+')').attr('selected', true);
with (untested)
$("#"+k+" option[id='"+arr[k]+"']").attr("selected", "selected");
<script>
require(['jquery'],function($){
$(document).ready(function(){
function getJsonFromUrl() {
var query = location.search.substr(1);
var result = {};
query.split("&").forEach(function(part) {
var item = part.split("=");
result[item[0]] = decodeURIComponent(item[1]);
});
return result;
}
var arr = getJsonFromUrl();
for (var k in arr){
if (arr.hasOwnProperty(k)) {
//alert("Key is " + k + ", value is" + arr[k]);
var label = $('.product-options-wrapper').find("span:contains('"+k+"')");
$(label).parents().eq(1).find('select option:contains('+arr[k]+')').attr('selected', true);
}
}
});
});
</script>

Resources