I have a listbox on a form that is editable and uses formula language to populate it. I use keywords, so the formula language takes values from 2 hidden fields and creates a single entry. For example, each entry is in format of
username | notesdn;uid
The listbox gets manipulated and new entries can be made at any time. In addition, entries can be moved up and down.
IF any new entries have been added to the listbox or any entries deleted from the listbox, all is good. The problem comes when entries in that listbox are moved up or down. When it’s time to step through the listbox and parse the data and save the data back to those same 2 hidden fields - it takes the ORIGINAL order of the listbox as it was BEFORE any entries were moved and that’s the order that gets saved back to the hidden fields.
As an extra data point here, there are 2 other listboxes whose entries also move up and down with the first listbox and those are saved back just fine and also are editable and formula language to populate.
For a quick and dirty setup of what I’ve got - the 2 hidden fields are listReviewer and idReviewer and this is how the “problem” listbox entries are generated:
wholeList := “”;
@For( n := 1; n <= @Elements( listReviewer ); n := n + 1;
Everything works great and the data is written back correctly EXCEPT in the case of entries being moved UP or DOWN. The up/down moving works fine as I have stepped through the options as it moves them and it’s good.
Subject: How do I grab values from “editable” listbox if entries moved?
it takes the ORIGINAL order of the listbox as it was BEFORE any entries were moved and that’s the
order that gets saved back to the hidden fields.
Post the code whereby these listbox entries get moved. Maybe you are not calling refresh before reading the listbox values? If you do not, I expect you would get the old order.
Subject: RE: How do I grab values from “editable” listbox if entries moved?
Here’s the function I call to MOVE the entries up and down:
function move( index, to ) {
var list = document.forms[0].RoutingPersons;
var total = list.options.length-1;
var list2 = document.forms[0].RoutingTitle;
var total2 = list2.options.length-1;
var list3 = document.forms[0].Rerouted;
var total3 = list3.options.length-1;
if (index == -1) return false;
if (to == +1 && index == total) return false;
if (to == -1 && index == 0) return false;
var items = new Array;
var values = new Array;
var items2 = new Array;
var values2 = new Array;
var items3 = new Array;
var values3 = new Array;
for (i = total; i >= 0; i--) {
items[i] = list.options[i].text;
values[i] = list.options[i].value;
items2[i] = list2.options[i].text;
values2[i] = list2.options[i].value;
items3[i] = list3.options[i].text;
values3[i] = list3.options[i].value;
}
for (i = total; i >= 0; i--) {
if (index == i) {
list.options[i + to] = new Option(items[i],values[i + to], 0, 1);
list.options[i] = new Option(items[i + to], values[i]);
list2.options[i + to] = new Option(items2[i],values2[i + to], 0, 1);
list2.options[i] = new Option(items2[i + to], values2[i]);
list3.options[i + to] = new Option(items3[i],values3[i + to], 0, 1);
list3.options[i] = new Option(items3[i + to], values3[i]);
i--;
}
else {
list.options[i] = new Option(items[i], values[i]);
list2.options[i] = new Option(items2[i], values2[i]);
list3.options[i] = new Option(items3[i], values3[i]);
}
}
list.focus();
}
The list boxes are already edited via this move function - why would I need to refresh the document? Surely then all my changes would be lost as be default the listboxes are generated by formula language that builds each entry from fields hidden on the form. These hidden fields are not edited upon each addition, deletion or movement.
That’s where I need this to work properly - once I save, that javascript runs through the current “live” listbox and writes back the data to those hidden fields.
Subject: RE: How do I grab values from “editable” listbox if entries moved?
Wouldn’t it be a bit simpler to use @Member to determine the index n of the element the user has selected, and move element n of each source field back (or forward) one element, and refresh the form?
Subject: RE: How do I grab values from “editable” listbox if entries moved?
This is a web app and javascript is used to handle all the form manipulations. The code works great and no refresh is done or needed. I don’t really know what the solution to this is… Joy!
Subject: RE: How do I grab values from “editable” listbox if entries moved?
OK, OK, here 'tis. The listbox is just a Notes Field of type listbox - I’ll be happy to make it all HTML if that will help any…
var f = document.forms[ 0 ];
var intNum = f.RoutingPersons.length;
var aryReviewer = new Array();
var aryID = new Array();
var aryTitle = new Array();
var aryReroute = new Array();
var aryDone = new Array();
// Grab all entries in all listboxes and store in array - so that I can write back to text field before saving
for ( var i = 0; i < intNum; i++ ) {
// Parse out keyword and grab pieces of reviewer listbox
// Cycle through the reviewers and parse out each entry since keywords were used with entry
// TEXT being the person's full name and VALUE being notesdn and uid separated by semicolon
// create array of UID and array of notesdn
var aryValues = f.RoutingPersons.options[ i ].value.split( ";" );
It all works fine, even when entries are added or deleted… But, the moving up/down doesn’t “stick” when stepping through the listbox even though the listbox is in it’s final order. I was pulling my hair out with this until I finally put an alert statement at the point where data was being pulled from the listbox and that’s when I found it wasn’t pulling it in the order as it appeared on the screen…
I would appreciate any help that could be offered.