PDA

View Full Version : datefield minvalue bug ?



nathanblogs
8 Dec 2009, 12:36 AM
Hi,

Sorry if this has been posted before but I searched the forums and couldn't find anything.

I have a datefield with a minvalue: new Date(), however when I select todays date it throws an error 'minText : "The date in this field must be equal to or after {0}",' where {0} is todays date.

Looking at the default validateValue for datefield gives:



if(this.minValue && time < this.minValue.getTime()){
this.markInvalid(String.format(this.minText, this.formatDate(this.minValue)));
return false;
}
if(this.maxValue && time > this.maxValue.getTime()){
this.markInvalid(String.format(this.maxText, this.formatDate(this.maxValue)));
return false;
}
I believe this should be



if(this.minValue && time <= this.minValue.getTime()){
this.markInvalid(String.format(this.minText, this.formatDate(this.minValue)));
return false;
}
if(this.maxValue && time >= this.maxValue.getTime()){
this.markInvalid(String.format(this.maxText, this.formatDate(this.maxValue)));
return false;
}
Is this a bug or am I doing something wrong ?

mystix
8 Dec 2009, 12:41 AM
it's doing exactly what you asked it to.

new Date() gives the exact moment in time in which it was evaluated.

i believe you were looking for "midnight of today" instead, i.e.


minvalue: new Date().clearTime()

nathanblogs
8 Dec 2009, 12:47 AM
it's doing exactly what you asked it to.

new Date() gives the exact moment in time in which it was evaluated.

i believe you were looking for "midnight of today" instead, i.e.


minvalue: new Date().clearTime()


Thanks that clears up alot and fixes my issue, but still shouldn't it still be <= and >= instead of > and < incase the user does it at 12:00am :P

mystix
8 Dec 2009, 12:53 AM
that doesn't make sense.

the date is allowed to take on both the minimum and maximum values.

using your code, you're disqualifying both the minimum and maximum dates as valid entries.

nathanblogs
8 Dec 2009, 3:21 AM
that doesn't make sense.

the date is allowed to take on both the minimum and maximum values.

using your code, you're disqualifying both the minimum and maximum dates as valid entries.

It's a very picky thing that probably can be ignored however the reason I say it is because the default error message is

'"The date in this field must be equal to or after {0}"'

Currently if it is equal, it will throw an error message. The chances of this actually happening are extremely slim however.