Skip to main content
Inspiring
November 30, 2007
Question

using today's date in selectableRange of dateField

  • November 30, 2007
  • 11 replies
  • 591 views
i'm having issues with the dateField component. i would like to dynamically specify today's date as the rangeEnd of the selectableRange, but i can't seem to get it to work.

can someone show me how to create a dateField component that does not allow you to select a date in the future?
This topic has been closed for replies.

11 replies

Inspiring
November 30, 2007
yea, i caught that as i placed this code into my actual application. they should re-word the docs on the selectableRange property. it doesn't even mention disabledRanges and in fact i knew nothing about it until you showed it to me here.
Inspiring
November 30, 2007
No problems..
No it wasn't importing it that I meant (it's just my habit to do it that way).

What I meant was having to do both of these:
my_df.disabledRanges = [ {rangeStart: endDate} ];
my_df.selectableRange = {rangeEnd:endDate};

before I got it working with just the selectableRange
Inspiring
November 30, 2007
BEAUTIFUL!!!! Wow, thank you so very much for your persistence on this one. That is so weird that you have to import it..... crazy. But it works, you rock, and I want to send you a Christmas present.

Thanks again!!!!
Inspiring
November 30, 2007
I think you're creating my_df inside home. So its out of scope for the code that follows, try this:

var my_df= home.createClassObject(mx.controls.DateField,"my_df",1);
Inspiring
November 30, 2007
ok, to take out any possibilities of targeting error, i created a new flash file. the only thing in it's library is a DateField component. here's my code and it's output. i can still select a date in the future.

Inspiring
November 30, 2007
It was working for me before. I didn't create the instance using the UIObject method - it was just in the authoring environment.

Don't ask me why this is necessary, but I think it will do what you want. You may want to take away the +1 if you just want it to be today. At the moment it includes tomorrow.

Inspiring
November 30, 2007
That last code works perfectly for me. Double-check that your DateField instance name is the same as the one you used in actionscript. In my example it was my_df
Inspiring
November 30, 2007
ok, what am i doing wrong? this code allows me to select a date in the future....


Inspiring
November 30, 2007
i lied.... it doesn't work. the syntax checks out fine, no compiler errors. however when you test it, it still allows you to select a date outside the specified range.
Inspiring
November 30, 2007
No problems. Great excuse to play with the Datefield component. Actually I think I did use it once already for something, I'd just forgotten.
Inspiring
November 30, 2007
i tried this before i posted and it wasn't working. there must have been something wrong with my syntax. thank you.
Inspiring
November 30, 2007
Or perhaps if I read your question a little bit more carefully, like this:

my_df.selectableRange = {rangeEnd: endDate};
Inspiring
November 30, 2007
I just gave it a try.

I'll just correct the code above to use rangeStart and it works as you want