1881 Posts in 637 Topics by 581 members
|Go to End|
3 August 2012 at 9:45pm
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 http://api.silverstripe.org/2.4/forms/fields-datetime/DateField.html#class_details) 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 - http://en.wikipedia.org/wiki/ISO_8601#Calendar_dates) 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 - http://www.silverstripe.org/archive/show/1197 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?
4 August 2012 at 6:39pm
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?
These are covered in a unit test so you can see an example of the behaviour - https://github.com/silverstripe/sapphire/blob/3.0/tests/forms/DateFieldTest.php#L24. Not sure if this passes through to the UI front end but PHP validation should fail (as the tests work).
I've updated the documentation request for date field to include your feedback (http://open.silverstripe.org/ticket/5830)
15 September 2012 at 5:01am Last edited: 15 September 2012 11:24pm
This is for SilverStripe 3.0.2, all trial and error
DateField should listen to the list of formats in zend date: framework/thirdparty/Zend/Date.php). I haven't tested them all, but the ones I did seem to work when using the default en_US locale.
For different (Dutch) locales, formats like 30 Sept. 2012 (dd MMM yyyy) do not seem to work, but all numeric formats are OK, which suggests the the dates are not locale aware, which they should be if I read zend-locale-format correctly(?). (you should be ok using d, dd, M, MM, y, yy, yyyy, FF)
This example works fine for me in the CMS, even in the GridField:
For the DatePicker calendar to appear in a different locale, the Zend Date locale files need to be present, which they aren't in the current build. For the Dutch locale this should be the file: framework/thirdparty/jquery-ui/minified/i18n/jquery.ui.datepicker-nl.min.js
Get all of them here: http://jquery-ui.googlecode.com/svn/trunk/ui/i18n/ (ticket here: http://open.silverstripe.org/ticket/7610)
Also there is the possibility of setting the Calender to a different locale using $dateField->setConfig('jslocale', 'nl'); But as the calendar listens to the current locale, it should hardly be necessary I think...
Ok, this is a version 3.0 reply - I totally missed the point that your question referred to version 2.4 - sorry about that. I'll leave it here because 3.0 users seem to stumble into these issues as well - unless you want me to remove the post?
|Go to Top|