getting the selected item in select1 outside a repeat group - odk

I am having some trouble implementing the relevants. I am suffering with getting the value of the selected item from my multiple select (the multiple select is outside the repeat group, the repeat group is where the implementation of relevant needs to be done).
I started off with a multiple select question ITEMLIST (readonly, all selected) outside a repeat group.
That limited my repeat loop (as intended) with the count of the selected items in the list (count-selected(/data/ITEMLIST))
I need to use the selected value of the first item(outside the repeat group) in the first repeat loop and so forth for all other iterations (managed to get the position - selected-at(/data/ITEMLIST, position(..)-1) and label - jr:choice(....) of the items in each iteration)
questions inside the repeat loop have relevants that if the item selected in the ITEMLIST is 1 then it needs to be shown else skipped, sth like.
I did some searches but could not implement anything.

Related

Oracle Apex checkbox

I have a page within my app with a Checkbox option.
The idea is basically to allow the user to select/unselect it if the change needs to be applied for every Sales Rep.
Something like this:
If checkbox is clicked = Change would be applied to all territories owned by the Rep
If checkbox is not clicked = Change would only be applied to the selected territory
I can't seem to get the checkbox clicked option to work.
I'm using an instr function to get a value out of it but it doesn't work:
select instr(':' ||:P11_CHECK_FOR_ALL|| ':', 'Request') into v_number_terr from dual;
if v_number_terr >0
(P11_CHECK_FOR_ALL is my checkbox Item / 'Request' is a word that's part of its label)
my checkbox pic
I'm trying to capture (in a process) whether the option is checked or not.
Could someone give me a hand please?
Thanks!
In apex a checkbox behaves just like a select list (with multiple selects possible). There is a display value and a return value. If nothing is selected, the page item value will be null. If one or more value are selected, the page item will contain a colon separated list of selected return values.
To handle the select list in a page process, the easiest is to split up the colon separated list in individual values using APEX_STRING.SPLIT
Example (untested):
DECLARE
l_check_for_all apex_t_varchar2;
BEGIN
l_check_for_all := apex_string.split(:P11_CHECK_FOR_ALL,':');
-- loop through the values. If nothing is selected then the COUNT will be 0 and nothing will be executed.
FOR i IN 1 .. l_check_for_all.COUNT LOOP
// do your pl/sql magic. You can reference the current item with l_check_for_all(i)
END LOOP;
END;

AS3 object passed as e.target does not match identical object passed through its array index

I'm designing an inventory system. right now, I need to test whether or not an item is in the inventory in order for the stage to know whether to instantiate that item in the particular level or not.
I add the items to the levels in groups, so this code is located within an array loop which "unloads" the "pack" of items corresponding to each level.
if (inv.indexOf(group[i]) == -1) {
//add item + item functionality
}
This method works when I add the item to the inventory such as this:
inv.push(group[i]);
if (inv.indexOf(group[i]) == -1) {
//add item + item functionality
}
But that doesn't work, because why would I add an item to the inventory without the user collecting it first? so the code is actually structured as so:
if (inv.indexOf(group[i]) == -1) {
//if item is not in inventory, add to stage
addChild(group[i]);
//when a user clicks this (any) item,
group[i].addEventListener(MouseEvent.CLICK, function itemFunctionality(e:MouseEvent){
//target item clicked
var item = e.target;
//add the item to the inventory
inv.push(item);
//sidenote: if i were to check inv.indexOf(item) here, i
//would get a positive index. unfortunately,
//i cant check whether the item is in the inventory
//after its already been added to the level...
item.removeEventListener(MouseEvent.CLICK, itemFunctionality);
});
}
The problem is when you leave and come back to the level, the items you already collected re-instantiate. If you collect an item again, the inventory adds a copy of the item you already collected.
The inv.indexOf(group[i]) checker doesn't understand that when the array loop reaches the corresponding, item group[i] == the object added to the inventory through inv.push(item) or in other words inv.push(e.target) (which, of course, I couldn't write directly into the code)...
When I trace whats inside of static array inv, what group[i] is within the array loop, or what e.target is, they all output the same type of item, "[object itemName]", signifying that the indexOf check SHOULD match up.
Update :
It appears if I make the items static as well as the array group they belong to this method works within the mouse event callback:
inv.push(item);
group.splice(group.indexOf(item), 1);
Though I had to remove the items and the item groups from their own class and put them inside of the level class itself... I feel this method kind of sucks because everything is getting disorganized and grouped into the same class.
Any helpful suggestions?
Objects are matched with their references. It means two objects created from the same class are not identical, they are different objects.
Assign unique IDs to your items and use them in your inventory. Like;
inv.push(item.id);
if (inv.indexOf(item.id) == -1) {
//add item + item functionality
}
Working with IDs is also better for serializing / deserializing.
There's your problem:
The problem is when you leave and come back to the level, the items you already collected re-instantiate.
Why would coming back to a level cause reinstatiation of any kind?
You should only ever once create each level object and part of that process should be creating all objects contained in that level. Visiting a level merely is an interaction with that object, which may include removing objects and adding them to the inventory. Once the objects are gone from the level, they are gone.
There's no reason to reinstantiate a level (or any of the objects within it) when revisiting it. If you are running into this problem because you are using a time line based approach with frames and gotoAndStop() to switch between levels then this is the core of your problem and you should stop doing that.

reorder array-table row and update database

I've been looking for a way to do something and I'm convinced I've been using the wrong search criteria to finding a solution...so, here I am.
I have a dropdown menu in a content management system that when a new page is created or position is edited, the database is updated with the new or edited value...this is all working great.
However, what I'd like to do is...when a number for the page position is changed from let's say, position 5 to position 1...the former position number 1 is changed to position number 2...and every position number for any pages remaining are renumbered accordingly.
So, my question is, how do I UPDATE my database so, whenever I change the position of the page in the dropdown menu, ALL position values get, I don't know, a +1...or something...and additionally, NOT allowing two position values to be the same...you know, there can be only one...
Thanks in advance...hope I didn't do too bad in explaining what I'd like to do :-)
Have you tried something like:
UPDATE my_table SET position=position+1 WHERE position>2 AND position<5
The where statement should be the new position & old position of the one you've just updated

jsTree - get only top level from checkboxes post

I am using jsTree with the checkboxes option inside of a regular form with this configuration:
"checkbox" : {
real_checkboxes : true,
two_state: false
}
I have only two levels of data (L1 and L2). If only some of the L2 items are checked, I get only those items (without the L1 item above them), which is fine. The problem is if all of the L2 items are checked, I get the top level item (L1) and all of the L2 items. I would like to get only the top level checked items, so that if all L2 items are checked I would get only the L1 item above them.
I saw there was a .get_checked ( context, get_all ) option but I am not sure how to post the values from this to the form.
As simple way would be to loop through the jQuery-result of .get_checked and concatenate the ids of each element to a comma separated String. You could then set the resulting String as the value of a hidden input field. You would have to split this String again on the server though.
You might also consider creating a jQuery selector for all (hidden) input elemens of checked elements and set them to unchecked. Something like
$("li.jstree-checked > ul input").attr('checked', false);
might work, though I haven't tried it out.

Compare different ways to remove selected items from System.Windows.Forms.ListBox

So far I've found 2 ways to delete selected items from a listbox (winform):
1.
ListBox.SelectedObjectCollection tempCollection = new ListBox.SelectedObjectCollection(myListBox);
for (int i = tempCollection.Count - 1; i >= 0; i--)
{
myListBox.Items.Remove(tempCollection[i]);
}
2.
while (myListBox.SelectedItems.Count > 0)
{
myListBox.Items.Remove(myListBox.SelectedItem);
// or
//myListBox.Items.Remove(myListBox.SelectedItems[0]);
}
The 2nd way is easy to understand, but the 1st one is strange for me. They're both work for me, I just want to know the difference?
The first way is written really strangely. It looks strange because it goes backwards. This is so that it doesn't upset the collection of selected items. The selected items collection isn't fully created, it's an Enumerable collection, and items come off it only when you ask for them. You can't use a foreach, because the collection of selected items keeps changing as you remove items.
I actually prefer the second way. Besides, whatever reads easier is easier to maintain. The first one reads: get the selected items, go through them backwards, removing each from the list.
The second one reads: while there are selected items, remove the first available selected item.
Much better the second way.

Resources