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

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

Issue 2905733002: [WebPayments] Disabling done button when form invalid (Closed)
Patch Set: nits 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/editor_view_controller.cc
diff --git a/chrome/browser/ui/views/payments/editor_view_controller.cc b/chrome/browser/ui/views/payments/editor_view_controller.cc
index 8d612816b8381938eab4a4a48b77e992ec9145c2..40bb5941d57ae378315a9706ce14d4075e823a8f 100644
--- a/chrome/browser/ui/views/payments/editor_view_controller.cc
+++ b/chrome/browser/ui/views/payments/editor_view_controller.cc
@@ -130,6 +130,18 @@ std::unique_ptr<views::View> EditorViewController::CreateExtraViewForField(
return nullptr;
}
+bool EditorViewController::ValidateInputFields() {
+ for (const auto& field : text_fields()) {
+ if (!field.first->IsValid())
+ return false;
+ }
+ for (const auto& field : comboboxes()) {
+ if (!field.first->IsValid())
+ return false;
+ }
+ return true;
+}
+
std::unique_ptr<views::Button> EditorViewController::CreatePrimaryButton() {
std::unique_ptr<views::Button> button(
views::MdTextButton::CreateSecondaryUiBlueButton(
@@ -209,11 +221,15 @@ EditorViewController::CreateComboboxForField(const EditorField& field) {
void EditorViewController::ContentsChanged(views::Textfield* sender,
const base::string16& new_contents) {
- static_cast<ValidatingTextfield*>(sender)->OnContentsChanged();
+ ValidatingTextfield* sender_cast = static_cast<ValidatingTextfield*>(sender);
+ sender_cast->OnContentsChanged();
+ primary_button()->SetEnabled(ValidateInputFields());
}
void EditorViewController::OnPerformAction(views::Combobox* sender) {
- static_cast<ValidatingCombobox*>(sender)->OnContentsChanged();
+ ValidatingCombobox* sender_cast = static_cast<ValidatingCombobox*>(sender);
+ sender_cast->OnContentsChanged();
+ primary_button()->SetEnabled(ValidateInputFields());
}
std::unique_ptr<views::View> EditorViewController::CreateEditorView() {
@@ -307,6 +323,9 @@ std::unique_ptr<views::View> EditorViewController::CreateEditorView() {
if (!initial_focus_field_view_)
initial_focus_field_view_ = first_field;
+ // Validate all fields and disable the primary (Done) button if necessary.
+ primary_button()->SetEnabled(ValidateInputFields());
+
// Adds the "* indicates a required field" label in "disabled" grey text.
std::unique_ptr<views::Label> required_field = base::MakeUnique<views::Label>(
l10n_util::GetStringUTF16(IDS_PAYMENTS_REQUIRED_FIELD_MESSAGE));

Powered by Google App Engine
This is Rietveld 408576698