Bug 769355 - Implements max attribute for <input type='date'>. r=mounir

This commit is contained in:
Raphael Catolino 2012-12-21 18:26:56 +01:00
parent 90a26c1967
commit 88b78d7a07
2 changed files with 54 additions and 14 deletions

View File

@ -1335,8 +1335,8 @@ nsHTMLInputElement::GetMinAsDouble() const
double
nsHTMLInputElement::GetMaxAsDouble() const
{
// Should only be used for <input type='number'> for the moment.
MOZ_ASSERT(mType == NS_FORM_INPUT_NUMBER);
// Should only be used for <input type='number'/'date'> for the moment.
MOZ_ASSERT(mType == NS_FORM_INPUT_NUMBER || mType == NS_FORM_INPUT_DATE);
if (!HasAttr(kNameSpaceID_None, nsGkAtoms::max)) {
return MOZ_DOUBLE_NaN();
@ -1345,9 +1345,8 @@ nsHTMLInputElement::GetMaxAsDouble() const
nsAutoString maxStr;
GetAttr(kNameSpaceID_None, nsGkAtoms::max, maxStr);
nsresult ec;
double max = maxStr.ToDouble(&ec);
return NS_SUCCEEDED(ec) ? max : MOZ_DOUBLE_NaN();
double max;
return ConvertStringToNumber(maxStr, max) ? max : MOZ_DOUBLE_NaN();
}
double
@ -4420,8 +4419,7 @@ nsHTMLInputElement::HasPatternMismatch() const
bool
nsHTMLInputElement::IsRangeOverflow() const
{
// Ignore <input type=date> until bug 769355 is fixed.
if (!DoesMinMaxApply() || mType == NS_FORM_INPUT_DATE) {
if (!DoesMinMaxApply()) {
return false;
}
@ -4699,11 +4697,18 @@ nsHTMLInputElement::GetValidationMessage(nsAString& aValidationMessage,
{
nsXPIDLString message;
double max = GetMaxAsDouble();
MOZ_ASSERT(!MOZ_DOUBLE_IS_NaN(max));
nsAutoString maxStr;
maxStr.AppendFloat(max);
if (mType == NS_FORM_INPUT_NUMBER) {
//We want to show the value as parsed when it's a number
double max = GetMaxAsDouble();
MOZ_ASSERT(!MOZ_DOUBLE_IS_NaN(max));
maxStr.AppendFloat(max);
} else if (mType == NS_FORM_INPUT_DATE) {
GetAttr(kNameSpaceID_None, nsGkAtoms::max, maxStr);
} else {
NS_NOTREACHED("Unexpected input type");
}
const PRUnichar* params[] = { maxStr.get() };
rv = nsContentUtils::FormatLocalizedString(nsContentUtils::eDOM_PROPERTIES,
@ -5196,7 +5201,7 @@ nsHTMLInputElement::UpdateHasRange()
{
mHasRange = false;
if (mType != NS_FORM_INPUT_NUMBER) {
if (mType != NS_FORM_INPUT_NUMBER && mType != NS_FORM_INPUT_DATE) {
return;
}

View File

@ -28,7 +28,7 @@ var types = [
[ 'email', false ],
[ 'password', false ],
[ 'datetime', true, true ],
[ 'date', true, true ],
[ 'date', true ],
[ 'month', true, true ],
[ 'week', true, true ],
[ 'time', true, true ],
@ -90,7 +90,12 @@ for (var data of types) {
checkValidity(input, true, apply, false);
input.max = '2';
if (input.type == 'date') {
input.max = '2012-06-27';
} else {
input.max = '2';
}
checkValidity(input, true, apply, apply);
if (input.type == 'url') {
@ -118,6 +123,36 @@ for (var data of types) {
checkValidity(input, true, apply, apply);
file.remove(false);
} else if (input.type == 'date') {
input.value = '2012-06-26';
checkValidity(input, true, apply, apply);
input.value = '2012-06-27';
checkValidity(input, true, apply, apply);
input.value = 'foo';
checkValidity(input, true, apply, apply);
input.value = '2012-06-28';
checkValidity(input, false, apply, apply);
input.max = '2012-06-30';
checkValidity(input, true, apply, apply);
input.value = '2012-07-05';
checkValidity(input, false, apply, apply);
input.value = '1000-01-01';
checkValidity(input, true, apply, apply);
input.value = '20120-01-01';
checkValidity(input, false, apply, apply);
input.max = '0050-01-01';
checkValidity(input, false, apply, apply);
input.value = '0049-01-01';
checkValidity(input, true, apply, apply);
} else {
input.value = '1';
checkValidity(input, true, apply, apply);