Reputation: 19885
How to create a DateField in flex, that would disable all the dates before today's current date.
<mx:DateField id="dateField2" yearNavigationEnabled="true"
disabledRanges="{[ {rangeEnd: new Date(dateBeforeCurrentDate} ]}" color="0x000000"/>
I understand I will have to do sometime like the code above. But I don't know how to get dateBeforeCurrentDate, so that all the date from yesterday will be disabled.
Please let me know.
Regards Zee
Upvotes: 1
Views: 6989
Reputation: 71
Something like this works:
disabledRanges="{[{rangeEnd: new Date((new Date()).getTime() - (1000*60*60*24))}]}"
selectableRange="{{rangeStart : new Date()}}"
You could probably extract the range into a bindable object.
Upvotes: 1
Reputation: 123
disabledRanges="{[{rangeEnd: new Date(new Date().getFullYear(),new Date().getMonth(),new Date().getDate()-1)}]}"
This works for Me :)
Upvotes: 0
Reputation: 19
I believe this should solve the problem:
<mx:DateField disabledRanges="{[{rangeEnd: new Date(null, null, new Date().date - 1)}]}"/>
Upvotes: 1
Reputation: 1
Why use any thing more complex than:
<mx:DateField disabledRanges="{[{rangeEnd: new Date()}]}"/>
<mx:DateField selectableRange="{{rangeStart : new Date()}}" y="50"/>
Upvotes: 0
Reputation: 14276
I think you're stuck with millisecond arithmetic. That's what's used in Adobe's docs:
function getYesterday():Date {
var today:Date = new Date();
var millisecondsPerDay:Number = 1000 * 60 * 60 * 24;
var yesterday:Date = new Date();
yesterday.setTime(today.getTime() - millisecondsPerDay);
}
You could probably pull in a library to do this (see, e.g. Flex Date Utils) if you're going to be doing any more date arithmetic.
Upvotes: 3
Reputation: 875
I guess you need this:
<mx:DateField disabledRanges="{[{rangeEnd: new Date()}]}"/>
Current date is just "new Date()".
Upvotes: 2