jsTree - get only top level from checkboxes post - checkbox

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.

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.

Expand specific rows in Angular-ui-grid

I'm using angular-ui-grid 3.0.5 with the treeview extension to display a tree. The data loads normally, everything works as expected, except that expandRow fails silently.
My use case is this: suppose we have a path like a > b > c and I need c shown to the user as preselected. I know the selection is correctly done because when I manually expand the parent rows, the child row is indeed selected.
Should I call expandAllRows, all rows would be expanded. However, calling expandRow with references on rows a and b taken from gridOptions.data leads to nothing happening: all rows will remain collapsed.
Is there any precaution to be taken that I have maybe overlooked, or is this a bug?
There's one mention in a closed issue that may be related to this but problem I'm having, but I'm not even sure it's related, given how dry the comment/solution was.
There's no example of using expandRow in the documentation but it's in both the API and the source code.
The gridRow objects mentioned in the documentation http://ui-grid.info/docs/#/api/ui.grid.treeBase.api:PublicApi are not the elements you put into the data array (though this seems to be not explained anywhere).
What the function expects is an object that the grid creates when building the tree, you can access them by looping through the grids treeBase.tree array. This will only be valid when the grid has built the tree, it seems, so it is not directly available when filling in the data, that's why registering a DataChangeCallback helps here https://github.com/angular-ui/ui-grid/issues/3051
// expand the top-level rows
// https://github.com/angular-ui/ui-grid/issues/3051
ctrl.gridApi.grid.registerDataChangeCallback(function() {
if (ctrl.gridApi.grid.treeBase.tree instanceof Array) {
angular.forEach(ctrl.gridApi.grid.treeBase.tree, function(node) {
if (node.row.treeLevel == 0) {
ctrl.gridApi.treeBase.expandRow(node.row);
}
});
}
});
self.onContentReady = function (e) {
e.component.expandRow(e.component.getKeyByRowIndex(0));
e.component.expandRow(e.component.getKeyByRowIndex(1));
};
selec which row you wanna expand

ListBox CollectionViewSource.Filter method question

I have a listbox defined in XAML and I filter its items using the following code from text obtained from a textbox:
if (list.Items.Count > 0)
{
CollectionViewSource.GetDefaultView(list.Items).Filter =
new Predicate<object>((item) => {
string valtoCheck = item.ToString();
return valtoCheck.StartsWith(filterText,
StringComparison.CurrentCultureIgnoreCase);
});
}
Everything works fine, except in the case where the filter finds no items matching the criteria.
ex. Lets say I have 4 items in the list : Rob,Bob,Andy,John.
When I enter Ro, the list filters accordingly (shows rob).
When I enter b, the list gets filtered appropriately (shows bob).
However, if i enter z (the target list becomes empty), I get an empty list which is correct; but then List.Items.Count is set to zero from that point on. The list becomes empty. I would assume that typing a replacement b should show me Bob but it does not; the list's items are set to empty as soon as I enter text that is not contained in any of the items in the listbox!
Am I missing something here?
I dont see you cannot eliminate the if condition check and just have
CollectionViewSource.GetDefaultView(list.Items).Filter =
new Predicate<object>((item) => {
string valtoCheck = item.ToString();
return valtoCheck.StartsWith(filterText,
StringComparison.CurrentCultureIgnoreCase);
});
It's hard to tell without seeing more of the surrounding code but issues like this are usually related to Refresh not being called at the right times. It also looks like you may be reassigning the Filter over and over instead of setting it once and refreshing when the filter text changes.

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