GessWurker1
Technical User
In a web app for which I'm responsible, I've been asked to sort contents of a form field by date descending using the date that starts each list item. I'm supposed to do this either onBlur or perhaps onSave because users are entering stuff willy-nilly. In any event, though I can very easily sort items alphabetically using javascript's array sort() method, sorting by date substring descending is whole 'nuther kettle of fish. My head is spinning trying to find a way to do this. 'Tis beyond me.
Here's an example of what I'd need to sort by date descending:
•01/21/2013 - something happened; something else happened on 01/30/2013.
•04/02/2014 - John J. buys a new car
•02/25/2014 - We went to a movie. It was awesome, but a better one comes out on 12/31/2019.
•05/21/2012 - Let's keep sorting things.
Let's say the above is all included in a form field with id=myActivities. I'd like to, onBlur, get this:
•04/02/2014 - John J. buys a new car
•02/25/2014 - We went to a movie. It was awesome, but a better one comes out on 12/31/2019.
•01/21/2013 - something happened; something else happened on 01/30/2013.
•05/21/2012 - Let's keep sorting things.
Any brilliant sorters out there? I'm at your mercy.
By the way, in a windows app I can use to edit/update existing content, I use the (slightly proprietary looking) jscript code below. It works great, but it's simple alphabetical sorting. Nothing to do with substring dates.
****************************************
var sortBox = new Array("Events");
function onRecordSave()
{
var i;
var es = Application.entrySeparator;
var fieldBox; // box object
var fieldString; // contents of the box
var entryArray; // array of field entries
// This loop will sort the entries in each box listed
// above, individually.
for (i = 0; i < sortBox.length; i++)
{
fieldBox = Form.boxes(sortBox);
if (fieldBox) // ensure that the box exists
{
fieldString = fieldBox.content;
entryArray = fieldString.split(es);
// sort the entries using the JScript sort method
entryArray = entryArray.sort();
fieldString = entryArray.join(es);
fieldBox.content = fieldString;
}
}
}
Here's an example of what I'd need to sort by date descending:
•01/21/2013 - something happened; something else happened on 01/30/2013.
•04/02/2014 - John J. buys a new car
•02/25/2014 - We went to a movie. It was awesome, but a better one comes out on 12/31/2019.
•05/21/2012 - Let's keep sorting things.
Let's say the above is all included in a form field with id=myActivities. I'd like to, onBlur, get this:
•04/02/2014 - John J. buys a new car
•02/25/2014 - We went to a movie. It was awesome, but a better one comes out on 12/31/2019.
•01/21/2013 - something happened; something else happened on 01/30/2013.
•05/21/2012 - Let's keep sorting things.
Any brilliant sorters out there? I'm at your mercy.
By the way, in a windows app I can use to edit/update existing content, I use the (slightly proprietary looking) jscript code below. It works great, but it's simple alphabetical sorting. Nothing to do with substring dates.
****************************************
var sortBox = new Array("Events");
function onRecordSave()
{
var i;
var es = Application.entrySeparator;
var fieldBox; // box object
var fieldString; // contents of the box
var entryArray; // array of field entries
// This loop will sort the entries in each box listed
// above, individually.
for (i = 0; i < sortBox.length; i++)
{
fieldBox = Form.boxes(sortBox);
if (fieldBox) // ensure that the box exists
{
fieldString = fieldBox.content;
entryArray = fieldString.split(es);
// sort the entries using the JScript sort method
entryArray = entryArray.sort();
fieldString = entryArray.join(es);
fieldBox.content = fieldString;
}
}
}