PDA

View Full Version : DateField's automatic parsing


ScreamingKettle
01-02-2009, 03:04 PM
Hi,
I was wondering if anyone has solved this issue I'm having...
I have an editable DateField on screen, but when I enter the date 3/1/09 I would like it to assume that 09 means 2009, not 1909. Is there a way to influence this, other than using a labelFunction? I assume it used Date.parse to convert the entered String into a Date. I like the fact it's quite intelligent in parsing the date that you enter in these fields, but I assumed it would take the minYear attribute of the DateField (in this case I used "1980") into consideration!

drkstr
01-02-2009, 08:32 PM
Sounds like a bug.

To work around it, you could extend DateField (http://opensource.adobe.com/svn/opensource/flex/sdk/branches/3.1.0/frameworks/projects/framework/src/mx/controls/DateField.as) and override the stringToDate function. Or if you prefer, you can assign an external function to the parseFunction property.


Best Regards,
~Aaron

ScreamingKettle
01-05-2009, 09:29 AM
Ahh, I was worried that might be the case. Ok, I may well do one of those. I might have a go at reporting this to wherever we report Flex bugs. I suppose now that it's open source I may well be expected to fix it myself!

Thanks for your help

drkstr
01-05-2009, 07:13 PM
Well "bug" might of been to strong a word. It's more of a gray area on what you would expect it to do.

It should be pretty easy to change the functionality so that the min and max year are taken into account. Just extend DateField and copy/paste the existing stringToDate function from that link I gave you. Towards the end just add the following:

yearNum = (yearNum < this.minYear)? this.minYear : yearNum;
yearNum = (yearNum > this.maxYear)? this.maxYear : yearNum;

//right above this line
var newDate:Date = new Date(yearNum, monthNum - 1, dayNum);

Or you can just return null if it's over/under the max/min which is what the function is supposed to do if an invalid date was entered.


Best Regards,
~Aaron