This is my first post on the SS forums so Mods please let me know if I have not provided all the relevant information and/or if there is a more suitable area for this thread.
This relates to the use of DateField in client facing forms/pages and in customising the CMS (though I presume they are exactly the same?).
At the best of times I can't help but feel that the SS Docs/API References could be greatly improved by having more detail and even examples. Some methods don't even have an explanation of the type of parameter they are intended to accept (eg. Int, String, Array, Object, Mixed) let alone a description of what format the param should follow. The Config options for DateField are just one example of this and im struggling to work out if I am deciphering the Docs incorrectly or if half of the options simply don't work/are pointless.
Below are the issues I am having and my understanding of how the options are intended to work. (See [url]http://api.silverstripe.org/2.4/forms/fields-datetime/DateField.html#class_details[/url]) If my understanding is incorrect please correct me as I would love to know how to use these options properly (if they work that is).
1) setConfig('minDate', ''); & setConfig('maxDate', '');
Despite literally hours of trying this setting in isolation and with other settings in use and trying multiple different date formats I have come to the conclusion that these simply do not work? When added nothing happens to enforce a limit on the date which can be selected using the calendar pop up and if I remember correctly I can still submit my form with dates outside of this range (So i don't think it works for validation purposes either?).
From the Docs it should accept "date value (in ISO format, or strtotime() compatible)" I have tried "YYYY-MM-DD" (ISO), "DD-MM-YYYY" (strtotime compatible) a timestamp and many other formats all to no avail? I had to remove all SS DateField references from my custom form and manually include jQuery UI/Calendar and configure it that way in order to get the min/max restriction to work.
'dateformat' (how the date is formatted for display) seems to work fine although some expanation of what "Date format compatible with Zend_Date" actually is would be useful. For anyone struggling I managed to get "dd-MM-YYYY" working however "DD-MM-YYYY" doesnt, as it messes up the days (displays '-04-2013' etc).
After many hours of trial and error using different date formats for 'datevalueformat' (the format for saving the date) I did what I probably should have done from the start and research what a "ISO format string used by dataValue()" (an ISO 8601 Date - [url]http://en.wikipedia.org/wiki/ISO_8601#Calendar_dates[/url]) and it would appear that there are only 3 options (YYYY-MM-DD, YYYYMMDD & YYYYMM - note the use of upper case D's for day just to add more confusion!). This in itself seems like a very bad idea to me, what if I want my Date to be stored as DD-MM-YYYY? Now before someone pipes up with either of the following:
- "Because a Date can only be stored in ISO format in a mySQL database, Duh!" - I know that which is why I am storing them in a field with datatype of Varchar(10) so I can store them as I want.
- "Why don't you store it in the DB using Date (ISO format) and then run it through a function for display to format it as you want?" - Because I am displaying it as a summary field in DataObjectManager in the CMS and because DOM manages its sorting by doing a new DB query every time with a sort clause and AJAXing the results in (don't even get me started on this one) it means that you cannot re-order the table columns using a value which is not stored in the DB!
That aside the 'datevalueformat' seems to have no use anyway as I have tried setting it to all three of the above options and all 3 lead to my date being saved as 06-04-2013 anyway? So it seems to also do nothing?
I have seen a suggestion here - [url]http://www.silverstripe.org/archive/show/1197[/url] which suggests that hacking around with the calendar-setup.js file may stop it from forcing the date to be returned for saving in YYYY-MM-DD format which I am about to try but surly it shouldn't come to this?
Does anyone have any good ideas of A) how to get around this issue, B) if I am missing something or C) an explanation as to why these options don't work?