Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/ui/views/payments/validating_textfield.h" | |
| 6 | |
| 7 #include "base/strings/utf_string_conversions.h" | |
|
anthonyvd
2017/02/08 15:28:28
unused?
Mathieu
2017/02/08 21:21:50
Done.
| |
| 8 | |
| 9 namespace payments { | |
| 10 | |
| 11 ValidatingTextfield::ValidatingTextfield( | |
| 12 ValidatingTextfield::Delegate* delegate) | |
| 13 : Textfield(), delegate_(delegate) {} | |
| 14 | |
| 15 void ValidatingTextfield::OnBlur() { | |
| 16 Textfield::OnBlur(); | |
| 17 | |
| 18 // The first validation of non-empty data should be on a blur. The subsequent | |
| 19 // validations will occur when the contents changes. | |
| 20 if (!was_validated_ && !text().empty()) { | |
| 21 was_validated_ = true; | |
| 22 Validate(); | |
| 23 } | |
| 24 } | |
| 25 | |
| 26 void ValidatingTextfield::OnContentsChanged() { | |
| 27 // Validation on every keystroke only happens if the field has been validated | |
| 28 // before as part of a blur. | |
| 29 if (!was_validated_) | |
| 30 return; | |
| 31 | |
| 32 Validate(); | |
| 33 } | |
| 34 | |
| 35 void ValidatingTextfield::Validate() { | |
| 36 // ValidateTextfield may have side-effects, such as displaying errors. | |
| 37 SetInvalid(!delegate_->ValidateTextfield(this)); | |
| 38 } | |
| 39 | |
| 40 } // namespace payments | |
| OLD | NEW |