Should clear an invalid string in a date field on blur
authortkent@chromium.org <tkent@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 13 Apr 2012 07:35:40 +0000 (07:35 +0000)
committertkent@chromium.org <tkent@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 13 Apr 2012 07:35:40 +0000 (07:35 +0000)
https://bugs.webkit.org/show_bug.cgi?id=83863

Reviewed by Kentaro Hara.

Source/WebCore:

Test: fast/forms/date/input-date-commit-valid-only.html

* html/DateInputType.cpp:
(WebCore::DateInputType::handleBlurEvent):
Reset the visible value. The code is same as NumberInputType::handleBlurEvent().

LayoutTests:

* fast/forms/date/input-date-commit-valid-only-expected.txt: Added.
* fast/forms/date/input-date-commit-valid-only.html: Added.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@114092 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/fast/forms/date/input-date-commit-valid-only-expected.txt [new file with mode: 0644]
LayoutTests/fast/forms/date/input-date-commit-valid-only.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/html/DateInputType.cpp

index dac35e8..32bcf58 100644 (file)
@@ -1,5 +1,15 @@
 2012-04-13  Kent Tamura  <tkent@chromium.org>
 
+        Should clear an invalid string in a date field on blur
+        https://bugs.webkit.org/show_bug.cgi?id=83863
+
+        Reviewed by Kentaro Hara.
+
+        * fast/forms/date/input-date-commit-valid-only-expected.txt: Added.
+        * fast/forms/date/input-date-commit-valid-only.html: Added.
+
+2012-04-13  Kent Tamura  <tkent@chromium.org>
+
         [Chromium] <input type=date> tests should pass.
 
         * platform/chromium/test_expectations.txt:
diff --git a/LayoutTests/fast/forms/date/input-date-commit-valid-only-expected.txt b/LayoutTests/fast/forms/date/input-date-commit-valid-only-expected.txt
new file mode 100644 (file)
index 0000000..6934545
--- /dev/null
@@ -0,0 +1,12 @@
+Type=date field should not accept invalid date strings though a user can type such strings
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS input.value is "2012-04-13"
+PASS document.getSelection().toString() == "+++" is false
+PASS input.value is ""
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/fast/forms/date/input-date-commit-valid-only.html b/LayoutTests/fast/forms/date/input-date-commit-valid-only.html
new file mode 100644 (file)
index 0000000..a17dfde
--- /dev/null
@@ -0,0 +1,32 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src="../../../fast/js/resources/js-test-pre.js"></script>
+</head>
+<body>
+<script>
+description('Type=date field should not accept invalid date strings though a user can type such strings');
+
+var parent = document.createElement('div');
+document.body.appendChild(parent);
+parent.innerHTML = '<input type="date" id="date" value="2012-04-13">';
+
+var input = document.getElementById('date');
+input.focus();
+document.execCommand('SelectAll', false, null);
+document.execCommand('InsertText', false, '+++');
+input.blur();
+shouldBe('input.value', '"2012-04-13"');
+input.focus();
+document.execCommand('SelectAll', false, null);
+shouldBeFalse('document.getSelection().toString() == "+++"');
+
+input.focus();
+document.execCommand('SelectAll', false, null);
+document.execCommand('InsertText', false, '');
+input.blur();
+shouldBe('input.value', '""');
+</script>
+<script src="../../../fast/js/resources/js-test-post.js"></script>
+</body>
+</html>
index 993b703..576c799 100644 (file)
@@ -1,3 +1,16 @@
+2012-04-13  Kent Tamura  <tkent@chromium.org>
+
+        Should clear an invalid string in a date field on blur
+        https://bugs.webkit.org/show_bug.cgi?id=83863
+
+        Reviewed by Kentaro Hara.
+
+        Test: fast/forms/date/input-date-commit-valid-only.html
+
+        * html/DateInputType.cpp:
+        (WebCore::DateInputType::handleBlurEvent):
+        Reset the visible value. The code is same as NumberInputType::handleBlurEvent().
+
 2012-04-12  Kent Tamura  <tkent@chromium.org>
 
         Calendar Picker: remove unnecessary code from calendarPicker.{css,js}
index 5abdc24..11b2c99 100644 (file)
@@ -132,6 +132,12 @@ void DateInputType::handleBlurEvent()
 {
     if (m_pickerElement)
         m_pickerElement->closePopup();
+
+    // Reset the renderer value, which might be unmatched with the element value.
+    element()->setFormControlValueMatchesRenderer(false);
+    // We need to reset the renderer value explicitly because an unacceptable
+    // renderer value should be purged before style calculation.
+    element()->updateInnerTextValue();
 }
 #endif // ENABLE(CALENDAR_PICKER)