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

Unified Diff: chrome/browser/ui/views/payments/validating_textfield.cc

Issue 2673753005: [Payments] Basic validation in the credit card editor. (Closed)
Patch Set: rouslan's comments Created 3 years, 10 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: chrome/browser/ui/views/payments/validating_textfield.cc
diff --git a/chrome/browser/ui/views/payments/validating_textfield.cc b/chrome/browser/ui/views/payments/validating_textfield.cc
new file mode 100644
index 0000000000000000000000000000000000000000..f164d7be4be28f15565f45396e2e763f192fd3cd
--- /dev/null
+++ b/chrome/browser/ui/views/payments/validating_textfield.cc
@@ -0,0 +1,40 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/ui/views/payments/validating_textfield.h"
+
+#include "base/strings/utf_string_conversions.h"
anthonyvd 2017/02/08 15:28:28 unused?
Mathieu 2017/02/08 21:21:50 Done.
+
+namespace payments {
+
+ValidatingTextfield::ValidatingTextfield(
+ ValidatingTextfield::Delegate* delegate)
+ : Textfield(), delegate_(delegate) {}
+
+void ValidatingTextfield::OnBlur() {
+ Textfield::OnBlur();
+
+ // The first validation of non-empty data should be on a blur. The subsequent
+ // validations will occur when the contents changes.
+ if (!was_validated_ && !text().empty()) {
+ was_validated_ = true;
+ Validate();
+ }
+}
+
+void ValidatingTextfield::OnContentsChanged() {
+ // Validation on every keystroke only happens if the field has been validated
+ // before as part of a blur.
+ if (!was_validated_)
+ return;
+
+ Validate();
+}
+
+void ValidatingTextfield::Validate() {
+ // ValidateTextfield may have side-effects, such as displaying errors.
+ SetInvalid(!delegate_->ValidateTextfield(this));
+}
+
+} // namespace payments

Powered by Google App Engine
This is Rietveld 408576698