Commit e459d0c1 authored by Seokho Song's avatar Seokho Song Committed by Commit Bot

Add form validation messages for min == max

The input validation has only been considered underflow or overflow.
If min and max values are equal and the user input value is different,
we should show a message that the values does not match.

In this CL, InputType will calculate 'value != min && min == max' to
check it must be same.

Bug: 1073923
Change-Id: Ia7e1e5e9ece70cd31034f3bda2c833dd36ed1d76
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2389281
Commit-Queue: Kent Tamura <tkent@chromium.org>
Reviewed-by: default avatarMason Freed <masonfreed@chromium.org>
Reviewed-by: default avatarKent Tamura <tkent@chromium.org>
Cr-Commit-Position: refs/heads/master@{#805588}
parent 6656dad8
......@@ -1011,6 +1011,12 @@ below:
<message name="IDS_FORM_VALIDATION_TYPE_MISMATCH_MULTIPLE_EMAIL" desc="Heading or short sentence shown there is a field which accepts multiple e-mail addresses and a user specified a value which is not a comma-separated e-mail addresses.">
Please enter a comma separated list of email addresses.
</message>
<message name="IDS_FORM_VALIDATION_VALUE_NOT_EQUAL" desc="Heading or short sentence shown when a form control value in a webpage needs to be equal to a minimum and maximum value specified by the page author, but a user specified a too small or large value.">
Value must be <ph name="VALUE">$1<ex>1</ex></ph>.
</message>
<message name="IDS_FORM_VALIDATION_VALUE_NOT_EQUAL_DATETIME" desc="Heading or short sentence shown when a form control value in a webpage needs to be equal to a minimum and maximum date/time value specified by the page author, but a user specified an earlier or later date/time.">
Value must be <ph name="VALUE_DATE_OR_TIME">$1<ex>02/09/2020</ex></ph>.
</message>
<message name="IDS_FORM_VALIDATION_RANGE_UNDERFLOW" desc="Heading or short sentence shown when a form control value in a webpage needs to be larger than or equal to a minimum value specified by the page author, but a user specified a too small value.">
Value must be greater than or equal to <ph name="MINIMUM">$1<ex>0</ex></ph>.
</message>
......
bfa666f6da5179560490129c14a2db4cc4816dcc
\ No newline at end of file
......@@ -94,6 +94,11 @@ bool BaseTemporalInputType::TypeMismatch() const {
return TypeMismatchFor(GetElement().value());
}
String BaseTemporalInputType::ValueNotEqualText(const Decimal& value) const {
return GetLocale().QueryString(IDS_FORM_VALIDATION_VALUE_NOT_EQUAL_DATETIME,
LocalizeValue(Serialize(value)));
}
String BaseTemporalInputType::RangeOverflowText(const Decimal& maximum) const {
return GetLocale().QueryString(IDS_FORM_VALIDATION_RANGE_OVERFLOW_DATETIME,
LocalizeValue(Serialize(maximum)));
......
......@@ -95,6 +95,7 @@ class BaseTemporalInputType : public InputType {
bool TypeMismatchFor(const String&) const override;
bool TypeMismatch() const override;
bool ValueMissing(const String&) const override;
String ValueNotEqualText(const Decimal& value) const override;
String RangeOverflowText(const Decimal& maximum) const override;
String RangeUnderflowText(const Decimal& minimum) const override;
String RangeInvalidText(const Decimal& minimum,
......
......@@ -336,6 +336,11 @@ String InputType::BadInputText() const {
return GetLocale().QueryString(IDS_FORM_VALIDATION_TYPE_MISMATCH);
}
String InputType::ValueNotEqualText(const Decimal& value) const {
NOTREACHED();
return String();
}
String InputType::RangeOverflowText(const Decimal&) const {
NOTREACHED();
return String();
......@@ -426,6 +431,12 @@ std::pair<String, String> InputType::ValidationMessage(
g_empty_string);
}
if (numeric_value != step_range.Minimum() &&
step_range.Minimum() == step_range.Maximum()) {
return std::make_pair(ValueNotEqualText(step_range.Minimum()),
g_empty_string);
}
if (numeric_value < step_range.Minimum())
return std::make_pair(RangeUnderflowText(step_range.Minimum()),
g_empty_string);
......
......@@ -143,6 +143,7 @@ class CORE_EXPORT InputType : public GarbageCollected<InputType> {
void StepUp(double, ExceptionState&);
void StepUpFromLayoutObject(int);
virtual String BadInputText() const;
virtual String ValueNotEqualText(const Decimal& value) const;
virtual String RangeOverflowText(const Decimal& maximum) const;
virtual String RangeUnderflowText(const Decimal& minimum) const;
virtual String ReversedRangeOutOfRangeText(const Decimal& minimum,
......
......@@ -334,6 +334,11 @@ String NumberInputType::BadInputText() const {
return GetLocale().QueryString(IDS_FORM_VALIDATION_BAD_INPUT_NUMBER);
}
String NumberInputType::ValueNotEqualText(const Decimal& value) const {
return GetLocale().QueryString(IDS_FORM_VALIDATION_VALUE_NOT_EQUAL,
LocalizeValue(Serialize(value)));
}
String NumberInputType::RangeOverflowText(const Decimal& maximum) const {
return GetLocale().QueryString(IDS_FORM_VALIDATION_RANGE_OVERFLOW,
LocalizeValue(Serialize(maximum)));
......
......@@ -73,6 +73,7 @@ class NumberInputType final : public TextFieldInputType {
void WarnIfValueIsInvalid(const String&) const override;
bool HasBadInput() const override;
String BadInputText() const override;
String ValueNotEqualText(const Decimal& value) const override;
String RangeOverflowText(const Decimal& maxmum) const override;
String RangeUnderflowText(const Decimal& minimum) const override;
bool SupportsPlaceholder() const override;
......
CONSOLE WARNING: line 119: The specified value "1999-01-02" cannot be parsed, or is out of range.
CONSOLE WARNING: line 127: The specified value "2000-01-01T00:00" cannot be parsed, or is out of range.
CONSOLE WARNING: line 135: The specified value "1999-01" cannot be parsed, or is out of range.
CONSOLE WARNING: line 143: The specified value "1999-W01" cannot be parsed, or is out of range.
CONSOLE WARNING: line 151: The specified value "06:00" cannot be parsed, or is out of range.
Test for validationMessage DOM property.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
......@@ -26,6 +31,19 @@ stepMismatch:
input stepMismatch: Please enter a valid value. The two nearest valid values are 0.1 and 0.2.
input stepMismatch: Please enter a valid value. The two nearest valid values are 0.1 and 0.2.
input stepMismatch: Please enter a valid value. The nearest valid value is 10.
rangeOverflow and rangeUnderflow:
input rangeOverflow and rangeUnderflow: Value must be 1.
input rangeOverflow and rangeUnderflow: Value must be 1.
input rangeOverflow and rangeUnderflow: Value must be 01/02/2000.
input rangeOverflow and rangeUnderflow: Value must be 01/02/2000.
input rangeOverflow and rangeUnderflow: Value must be 01/02/2000, 12:00 AM.
input rangeOverflow and rangeUnderflow: Value must be 01/02/2000, 12:00 AM.
input rangeOverflow and rangeUnderflow: Value must be January 2000.
input rangeOverflow and rangeUnderflow: Value must be January 2000.
input rangeOverflow and rangeUnderflow: Value must be Week 01, 2000.
input rangeOverflow and rangeUnderflow: Value must be Week 01, 2000.
input rangeOverflow and rangeUnderflow: Value must be 7:00 AM.
input rangeOverflow and rangeUnderflow: Value must be 7:00 AM.
tooLong:
input tooLong: Please shorten this text to 3 characters or less (you are currently using 5 characters).
input tooLong: Please shorten this text to 2 characters or less (you are currently using 3 characters).
......
......@@ -99,6 +99,58 @@ numberInput.max = "10.02";
numberInput.value = "10.01";
debug("input stepMismatch: " + numberInput.validationMessage);
debug("rangeOverflow and rangeUnderflow:");
numberInput.min = "1"
numberInput.max = "1";
numberInput.value = "2";
debug("input rangeOverflow and rangeUnderflow: " + numberInput.validationMessage);
numberInput.value = "-2";
debug("input rangeOverflow and rangeUnderflow: " + numberInput.validationMessage);
var dateInput = document.createElement("input");
dateInput.type = "date";
form.appendChild(dateInput);
dateInput.required = true;
dateInput.min = "2000-01-02"
dateInput.max = "2000-01-02";
dateInput.value = "2000-01-03";
debug("input rangeOverflow and rangeUnderflow: " + dateInput.validationMessage);
numberInput.value = "1999-01-02";
debug("input rangeOverflow and rangeUnderflow: " + dateInput.validationMessage);
dateInput.type = "datetime-local"
dateInput.min = "2000-01-02T00:00"
dateInput.max = "2000-01-02T00:00"
dateInput.value = "2000-01-02T10:00"
debug("input rangeOverflow and rangeUnderflow: " + dateInput.validationMessage);
numberInput.value = "2000-01-01T00:00"
debug("input rangeOverflow and rangeUnderflow: " + dateInput.validationMessage);
dateInput.type = "month"
dateInput.min = "2000-01"
dateInput.max = "2000-01"
dateInput.value = "2000-02"
debug("input rangeOverflow and rangeUnderflow: " + dateInput.validationMessage);
numberInput.value = "1999-01"
debug("input rangeOverflow and rangeUnderflow: " + dateInput.validationMessage);
dateInput.type = "week"
dateInput.min = "2000-W01"
dateInput.max = "2000-W01"
dateInput.value = "2000-W02"
debug("input rangeOverflow and rangeUnderflow: " + dateInput.validationMessage);
numberInput.value = "1999-W01"
debug("input rangeOverflow and rangeUnderflow: " + dateInput.validationMessage);
dateInput.type = "time"
dateInput.min = "07:00"
dateInput.max = "07:00"
dateInput.value = "08:00"
debug("input rangeOverflow and rangeUnderflow: " + dateInput.validationMessage);
numberInput.value = "06:00"
debug("input rangeOverflow and rangeUnderflow: " + dateInput.validationMessage);
debug("tooLong:");
var inputWithMax = document.createElement("input");
inputWithMax.maxLength = 3;
......
CONSOLE WARNING: line 119: The specified value "1999-01-02" cannot be parsed, or is out of range.
CONSOLE WARNING: line 127: The specified value "2000-01-01T00:00" cannot be parsed, or is out of range.
CONSOLE WARNING: line 135: The specified value "1999-01" cannot be parsed, or is out of range.
CONSOLE WARNING: line 143: The specified value "1999-W01" cannot be parsed, or is out of range.
CONSOLE WARNING: line 151: The specified value "06:00" cannot be parsed, or is out of range.
Test for validationMessage DOM property.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
input patternMismatch: Please match the requested format.
input valueMissing: Please fill out this field.
textarea valueMissing: Please fill out this field.
select valueMissing: Please select an item in the list.
input typeMismatch for incorrectValue: Please include an '@' in the email address. 'incorrectValue' is missing an '@'.
input typeMismatch for @xn--fsq.com: Please enter a part followed by '@'. '@例.com' is incomplete.
input typeMismatch for user@: Please enter a part following '@'. 'user@' is incomplete.
input typeMismatch for user@example*.com: A part following '@' should not contain the symbol '*'.
input typeMismatch for user🙇@example.com: A part followed by '@' should not contain the symbol '🙇'.
input typeMismatch for user@example.com: A part followed by '@' should not contain the symbol ''.
input typeMismatch for user@.example.com: '.' is used at a wrong position in '.example.com'.
input typeMismatch for user@example.com.: '.' is used at a wrong position in 'example.com.'.
input typeMismatch for user@xn--z8ja1psq..com: '.' is used at a wrong position in 'ぐーぐる..com'.
input typeMismatch for foo@example.com,,bar@example.com: Please enter a non-empty email address.
input typeMismatch for ,foo@example.com: Please enter a non-empty email address.
input typeMismatch for foo@example.com,: Please enter a non-empty email address.
input typeMismatch for foo@example.com,bar@..example.com: '.' is used at a wrong position in '..example.com'.
input badInput: Please enter a number.
badInput and valueMissing:
PASS numberInput.validationMessage is nonRequiredBadInputMessage
stepMismatch:
input stepMismatch: Please enter a valid value. The two nearest valid values are 0.1 and 0.2.
input stepMismatch: Please enter a valid value. The two nearest valid values are 0.1 and 0.2.
input stepMismatch: Please enter a valid value. The nearest valid value is 10.
rangeOverflow and rangeUnderflow:
input rangeOverflow and rangeUnderflow: Value must be 1.
input rangeOverflow and rangeUnderflow: Value must be 1.
input rangeOverflow and rangeUnderflow: Value must be 01/02/2000.
input rangeOverflow and rangeUnderflow: Value must be 01/02/2000.
input rangeOverflow and rangeUnderflow: Value must be 01/02/2000, 12:00 AM.
input rangeOverflow and rangeUnderflow: Value must be 01/02/2000, 12:00 AM.
input rangeOverflow and rangeUnderflow: Value must be January 2000.
input rangeOverflow and rangeUnderflow: Value must be January 2000.
input rangeOverflow and rangeUnderflow: Value must be Week 01, 2000.
input rangeOverflow and rangeUnderflow: Value must be Week 01, 2000.
input rangeOverflow and rangeUnderflow: Value must be 7:00 AM.
input rangeOverflow and rangeUnderflow: Value must be 7:00 AM.
tooLong:
input tooLong: Please shorten this text to 3 characters or less (you are currently using 5 characters).
input tooLong: Please shorten this text to 2 characters or less (you are currently using 3 characters).
input tooLong: Please shorten this text to ٢ characters or less (you are currently using ٣ characters).
textarea tooLong: Please shorten this text to 3 characters or less (you are currently using 4 characters).
tooShort:
input tooShort: Please lengthen this text to 3 characters or more (you are currently using 1 character).
input tooShort: Please lengthen this text to 4 characters or more (you are currently using 3 characters).
input tooShort: Please lengthen this text to ٤ characters or more (you are currently using ٣ characters).
textarea tooShort: Please lengthen this text to 4 characters or more (you are currently using 2 characters).
PASS but.validationMessage is ''
PASS anoninput.validationMessage is ''
PASS happyFieldset.validationMessage is ''
PASS happySelect.validationMessage is ''
PASS happyOutput.validationMessage is ''
PASS happyObject.validationMessage is ''
PASS successfullyParsed is true
TEST COMPLETE
CONSOLE WARNING: line 119: The specified value "1999-01-02" cannot be parsed, or is out of range.
CONSOLE WARNING: line 127: The specified value "2000-01-01T00:00" cannot be parsed, or is out of range.
CONSOLE WARNING: line 135: The specified value "1999-01" cannot be parsed, or is out of range.
CONSOLE WARNING: line 143: The specified value "1999-W01" cannot be parsed, or is out of range.
CONSOLE WARNING: line 151: The specified value "06:00" cannot be parsed, or is out of range.
Test for validationMessage DOM property.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
input patternMismatch: Please match the requested format.
input valueMissing: Please fill out this field.
textarea valueMissing: Please fill out this field.
select valueMissing: Please select an item in the list.
input typeMismatch for incorrectValue: Please include an '@' in the email address. 'incorrectValue' is missing an '@'.
input typeMismatch for @xn--fsq.com: Please enter a part followed by '@'. '@例.com' is incomplete.
input typeMismatch for user@: Please enter a part following '@'. 'user@' is incomplete.
input typeMismatch for user@example*.com: A part following '@' should not contain the symbol '*'.
input typeMismatch for user🙇@example.com: A part followed by '@' should not contain the symbol '🙇'.
input typeMismatch for user@example.com: A part followed by '@' should not contain the symbol ''.
input typeMismatch for user@.example.com: '.' is used at a wrong position in '.example.com'.
input typeMismatch for user@example.com.: '.' is used at a wrong position in 'example.com.'.
input typeMismatch for user@xn--z8ja1psq..com: '.' is used at a wrong position in 'ぐーぐる..com'.
input typeMismatch for foo@example.com,,bar@example.com: Please enter a non-empty email address.
input typeMismatch for ,foo@example.com: Please enter a non-empty email address.
input typeMismatch for foo@example.com,: Please enter a non-empty email address.
input typeMismatch for foo@example.com,bar@..example.com: '.' is used at a wrong position in '..example.com'.
input badInput: Please enter a number.
badInput and valueMissing:
PASS numberInput.validationMessage is nonRequiredBadInputMessage
stepMismatch:
input stepMismatch: Please enter a valid value. The two nearest valid values are 0.1 and 0.2.
input stepMismatch: Please enter a valid value. The two nearest valid values are 0.1 and 0.2.
input stepMismatch: Please enter a valid value. The nearest valid value is 10.
rangeOverflow and rangeUnderflow:
input rangeOverflow and rangeUnderflow: Value must be 1.
input rangeOverflow and rangeUnderflow: Value must be 1.
input rangeOverflow and rangeUnderflow: Value must be 01/02/2000.
input rangeOverflow and rangeUnderflow: Value must be 01/02/2000.
input rangeOverflow and rangeUnderflow: Value must be 01/02/2000 12:00 AM.
input rangeOverflow and rangeUnderflow: Value must be 01/02/2000 12:00 AM.
input rangeOverflow and rangeUnderflow: Value must be January 2000.
input rangeOverflow and rangeUnderflow: Value must be January 2000.
input rangeOverflow and rangeUnderflow: Value must be Week 01, 2000.
input rangeOverflow and rangeUnderflow: Value must be Week 01, 2000.
input rangeOverflow and rangeUnderflow: Value must be 7:00 AM.
input rangeOverflow and rangeUnderflow: Value must be 7:00 AM.
tooLong:
input tooLong: Please shorten this text to 3 characters or less (you are currently using 5 characters).
input tooLong: Please shorten this text to 2 characters or less (you are currently using 3 characters).
input tooLong: Please shorten this text to ٢ characters or less (you are currently using ٣ characters).
textarea tooLong: Please shorten this text to 3 characters or less (you are currently using 4 characters).
tooShort:
input tooShort: Please lengthen this text to 3 characters or more (you are currently using 1 character).
input tooShort: Please lengthen this text to 4 characters or more (you are currently using 3 characters).
input tooShort: Please lengthen this text to ٤ characters or more (you are currently using ٣ characters).
textarea tooShort: Please lengthen this text to 4 characters or more (you are currently using 2 characters).
PASS but.validationMessage is ''
PASS anoninput.validationMessage is ''
PASS happyFieldset.validationMessage is ''
PASS happySelect.validationMessage is ''
PASS happyOutput.validationMessage is ''
PASS happyObject.validationMessage is ''
PASS successfullyParsed is true
TEST COMPLETE
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment