This topic is locked
[SOLVED]

 date picker sort dates descending

3/27/2012 11:49:12 AM
PHPRunner General questions
W
Webmaster .at. CS author

Is it possible to revert the date picker dropdown so it display from e.g. 2042..downto say 1982.
Its not possible to 'fake' this in the properties of the date-field. (with negative values etc, you can not say it has to sort descending)
Is it possible to set or create this somewhere else? (even in the code)

C
cgphp 3/27/2012

In the "Javascript onload" event of the add/edit page, enter the followig code:

var year_options = $("#yearvalue_YOURDATEFIELDNAME_1 option[value!='']").sort(function(p1,p2) {

if (p1.text < p2.text) return 1;

else if (p1.text > p2.text) return -1;

else return 0;

});
$("#yearvalue_YOURDATEFIELDNAME_1").empty().append(year_options).prepend("<option value=''></option>");
$("#yearvalue_YOURDATEFIELDNAME_1 option:first").attr('selected','selected');


Replace YOURDATEFIELDNAME with the name of the date field.

W
Webmaster .at. CS author 3/28/2012

Cristian,
Thank you for your code, it produces the output I need.

However, I would like this code to work for all of the date-fields in my application. Also, after a new generation, the generated year-field gets different postfix numbers. E.g. first the field is called datumAanvraag_15, after another generation the field is called datumAanvraag_56. Is it possible to generalize the code?

C
cgphp 3/28/2012
var year_options = $("select[id^='yearvalue_YOURDATEFIELDNAME'] option[value!='']").sort(function(p1,p2) {

if (p1.text < p2.text) return 1;

else if (p1.text > p2.text) return -1;

else return 0;

});
$("select[id^='yearvalue_YOURDATEFIELDNAME']").empty().append(year_options).prepend("<option value=''></option>");
$("select[id^='yearvalue_YOURDATEFIELDNAME'] option:first").attr('selected','selected');
W
Webmaster .at. CS author 3/29/2012

Cristian,
You're a real JS-wizzard. <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=65309&image=1&table=forumreplies' class='bbcemoticon' alt=':D' />
I used this code:
var ctrl = Runner.getControl(pageid, fieldName);
var yearField="#yearvalue"+fieldName+"_"+ctrl.id;
Thanks!