Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(446)

Unified Diff: Source/core/html/forms/BaseTextInputType.cpp

Issue 435753003: Implement minlength for <input> and <textarea>. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Add layout tests for minlength & maxlength together; fix comments Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/core/html/forms/BaseTextInputType.cpp
diff --git a/Source/core/html/forms/BaseTextInputType.cpp b/Source/core/html/forms/BaseTextInputType.cpp
index 9ee4ab54e517401cb94de4ff6f30f0ff78f1f01a..fe85c790e33418ca356b201e4ecfbf0c25fe9f0a 100644
--- a/Source/core/html/forms/BaseTextInputType.cpp
+++ b/Source/core/html/forms/BaseTextInputType.cpp
@@ -37,6 +37,11 @@ int BaseTextInputType::maxLength() const
return element().maxLength();
}
+int BaseTextInputType::minLength() const
+{
+ return element().minLength();
+}
+
bool BaseTextInputType::tooLong(const String& value, HTMLTextFormControlElement::NeedsToCheckDirtyFlag check) const
{
int max = element().maxLength();
@@ -51,6 +56,22 @@ bool BaseTextInputType::tooLong(const String& value, HTMLTextFormControlElement:
return value.length() > static_cast<unsigned>(max);
}
+bool BaseTextInputType::tooShort(const String& value, HTMLTextFormControlElement::NeedsToCheckDirtyFlag check) const
+{
+ int min = element().minLength();
+ if (min <= 0)
+ return false;
+ if (check == HTMLTextFormControlElement::CheckDirtyFlag) {
+ // Return false for the default value or a value set by a script even if
+ // it is shorter than minLength.
+ if (!element().hasDirtyValue() || !element().lastChangeWasUserEdit())
+ return false;
+ }
+ // An empty string is excluded from minlength check.
+ unsigned len = value.length();
+ return len > 0 && len < static_cast<unsigned>(min);
+}
+
bool BaseTextInputType::patternMismatch(const String& value) const
{
const AtomicString& rawPattern = element().fastGetAttribute(patternAttr);

Powered by Google App Engine
This is Rietveld 408576698