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

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

Issue 2896263002: [Payments] Changes to validation in the Credit Card editor (Closed)
Patch Set: rebase Created 3 years, 7 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
index 15f742b90f8c2e21e4d2f518768c8e084c848587..efce2f2be8f9ce7e5a0cabfc314bec6498155b60 100644
--- a/chrome/browser/ui/views/payments/validating_textfield.cc
+++ b/chrome/browser/ui/views/payments/validating_textfield.cc
@@ -16,14 +16,11 @@ ValidatingTextfield::~ValidatingTextfield() {}
void ValidatingTextfield::OnBlur() {
Textfield::OnBlur();
+ was_blurred_ = true;
- // The first validation should be on a blur. The subsequent validations will
- // occur when the content changes. Do not validate if the view is being
- // removed.
- if (!was_blurred_ && !being_removed_) {
- was_blurred_ = true;
+ // Do not validate if the view is being removed.
+ if (!being_removed_)
Validate();
- }
if (!text().empty() && delegate_->ShouldFormat())
SetText(delegate_->Format(text()));
@@ -36,28 +33,22 @@ void ValidatingTextfield::ViewHierarchyChanged(
}
void ValidatingTextfield::OnContentsChanged() {
+ // This is called on every keystroke.
if (!text().empty() && GetCursorPosition() == text().length() &&
delegate_->ShouldFormat()) {
SetText(delegate_->Format(text()));
}
- // Validation on every keystroke only happens if the field has been validated
- // before as part of a blur.
- if (!was_blurred_)
- return;
-
Validate();
}
bool ValidatingTextfield::IsValid() {
- bool valid = delegate_->IsValidTextfield(this);
- SetInvalid(!valid);
- return valid;
+ return delegate_->IsValidTextfield(this);
}
void ValidatingTextfield::Validate() {
// TextfieldValueChanged may have side-effects, such as displaying errors.
- SetInvalid(!delegate_->TextfieldValueChanged(this));
+ SetInvalid(!delegate_->TextfieldValueChanged(this, was_blurred_));
}
} // namespace payments

Powered by Google App Engine
This is Rietveld 408576698