Zeeshan Rang
Zeeshan Rang

Reputation: 19885

Disable all dates before the currentDate in DateField

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

Answers (6)

MLS
MLS

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

Kamran Aslam
Kamran Aslam

Reputation: 123

disabledRanges="{[{rangeEnd: new Date(new Date().getFullYear(),new Date().getMonth(),new Date().getDate()-1)}]}"

This works for Me :)

Upvotes: 0

Menia9
Menia9

Reputation: 19

I believe this should solve the problem:

<mx:DateField disabledRanges="{[{rangeEnd: new Date(null, null, new Date().date - 1)}]}"/>

Upvotes: 1

Vincy Oommen
Vincy Oommen

Reputation: 1

Why use any thing more complex than:

<mx:DateField disabledRanges="{[{rangeEnd: new Date()}]}"/>
<mx:DateField selectableRange="{{rangeStart : new Date()}}" y="50"/> 

www.nucleusplus.com

Upvotes: 0

Michael Brewer-Davis
Michael Brewer-Davis

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

invisible_hand
invisible_hand

Reputation: 875

I guess you need this:

<mx:DateField disabledRanges="{[{rangeEnd: new Date()}]}"/>

Current date is just "new Date()".

Upvotes: 2

Related Questions