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

Side by Side Diff: chrome/browser/ui/views/payments/shipping_address_editor_view_controller.cc

Issue 2773383002: [Payments] In shipping address editor, enable required + phone validation. (Closed)
Patch Set: Initial Created 3 years, 9 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 unified diff | Download patch
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/views/payments/shipping_address_editor_view_controll er.h" 5 #include "chrome/browser/ui/views/payments/shipping_address_editor_view_controll er.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
(...skipping 15 matching lines...) Expand all
26 #include "components/autofill/core/browser/autofill_address_util.h" 26 #include "components/autofill/core/browser/autofill_address_util.h"
27 #include "components/autofill/core/browser/autofill_country.h" 27 #include "components/autofill/core/browser/autofill_country.h"
28 #include "components/autofill/core/browser/autofill_type.h" 28 #include "components/autofill/core/browser/autofill_type.h"
29 #include "components/autofill/core/browser/country_combobox_model.h" 29 #include "components/autofill/core/browser/country_combobox_model.h"
30 #include "components/autofill/core/browser/field_types.h" 30 #include "components/autofill/core/browser/field_types.h"
31 #include "components/autofill/core/browser/personal_data_manager.h" 31 #include "components/autofill/core/browser/personal_data_manager.h"
32 #include "components/autofill/core/browser/region_combobox_model.h" 32 #include "components/autofill/core/browser/region_combobox_model.h"
33 #include "components/autofill/core/browser/validation.h" 33 #include "components/autofill/core/browser/validation.h"
34 #include "components/autofill/core/common/autofill_constants.h" 34 #include "components/autofill/core/common/autofill_constants.h"
35 #include "components/payments/content/payment_request_state.h" 35 #include "components/payments/content/payment_request_state.h"
36 #include "components/strings/grit/components_strings.h"
36 #include "content/public/browser/web_contents.h" 37 #include "content/public/browser/web_contents.h"
37 #include "third_party/libaddressinput/chromium/chrome_metadata_source.h" 38 #include "third_party/libaddressinput/chromium/chrome_metadata_source.h"
38 #include "third_party/libaddressinput/chromium/chrome_storage_impl.h" 39 #include "third_party/libaddressinput/chromium/chrome_storage_impl.h"
39 #include "third_party/libaddressinput/messages.h" 40 #include "third_party/libaddressinput/messages.h"
40 #include "ui/base/l10n/l10n_util.h" 41 #include "ui/base/l10n/l10n_util.h"
41 #include "ui/views/controls/textfield/textfield.h" 42 #include "ui/views/controls/textfield/textfield.h"
42 43
43 namespace payments { 44 namespace payments {
44 45
45 namespace { 46 namespace {
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 284
284 // The editor can't be updated while in the middle of a combobox event. 285 // The editor can't be updated while in the middle of a combobox event.
285 base::ThreadTaskRunnerHandle::Get()->PostTask( 286 base::ThreadTaskRunnerHandle::Get()->PostTask(
286 FROM_HERE, 287 FROM_HERE,
287 base::Bind(&ShippingAddressEditorViewController::UpdateEditorView, 288 base::Bind(&ShippingAddressEditorViewController::UpdateEditorView,
288 base::Unretained(this))); 289 base::Unretained(this)));
289 } 290 }
290 291
291 ShippingAddressEditorViewController::ShippingAddressValidationDelegate:: 292 ShippingAddressEditorViewController::ShippingAddressValidationDelegate::
292 ShippingAddressValidationDelegate( 293 ShippingAddressValidationDelegate(
293 ShippingAddressEditorViewController* parent, 294 ShippingAddressEditorViewController* controller,
294 const EditorField& field) 295 const EditorField& field)
295 : field_(field) /* TODO(mad): Bring back when needed:, parent_(parent) */ {} 296 : field_(field), controller_(controller) {}
296 297
297 ShippingAddressEditorViewController::ShippingAddressValidationDelegate:: 298 ShippingAddressEditorViewController::ShippingAddressValidationDelegate::
298 ~ShippingAddressValidationDelegate() {} 299 ~ShippingAddressValidationDelegate() {}
299 300
300 bool ShippingAddressEditorViewController::ShippingAddressValidationDelegate:: 301 bool ShippingAddressEditorViewController::ShippingAddressValidationDelegate::
301 ValidateTextfield(views::Textfield* textfield) { 302 ValidateTextfield(views::Textfield* textfield) {
302 return ValidateValue(textfield->text()); 303 return ValidateValue(textfield->text());
303 } 304 }
304 305
305 bool ShippingAddressEditorViewController::ShippingAddressValidationDelegate:: 306 bool ShippingAddressEditorViewController::ShippingAddressValidationDelegate::
306 ValidateCombobox(views::Combobox* combobox) { 307 ValidateCombobox(views::Combobox* combobox) {
307 return ValidateValue(combobox->GetTextForRow(combobox->selected_index())); 308 return ValidateValue(combobox->GetTextForRow(combobox->selected_index()));
308 } 309 }
309 310
310 bool ShippingAddressEditorViewController::ShippingAddressValidationDelegate:: 311 bool ShippingAddressEditorViewController::ShippingAddressValidationDelegate::
311 ValidateValue(const base::string16& value) { 312 ValidateValue(const base::string16& value) {
312 // TODO(crbug.com/703754) add phone validation. 313 if (!value.empty()) {
313 // TODO(crbug.com/703756): Display "required" error if applicable. 314 if (field_.type == autofill::PHONE_HOME_NUMBER &&
314 return !field_.required || !value.empty(); 315 !autofill::IsValidPhoneNumber(
316 value,
317 controller_->country_codes_[controller_->chosen_country_index_])) {
318 controller_->DisplayErrorMessageForField(
319 field_, l10n_util::GetStringUTF16(
320 IDS_PAYMENTS_PHONE_INVALID_VALIDATION_MESSAGE));
321 return false;
322 }
323 // As long as other field types are non-empty, they are valid.
324 return true;
325 }
326
327 bool is_required_valid = !field_.required;
MAD 2017/03/27 13:29:13 Why not simply return true here when !field.requir
Mathieu 2017/03/27 13:39:03 I need to "clear" the suggestion if it's valid. Th
328 const base::string16 displayed_message =
329 is_required_valid ? base::ASCIIToUTF16("")
330 : l10n_util::GetStringUTF16(
331 IDS_PAYMENTS_FIELD_REQUIRED_VALIDATION_MESSAGE);
332 controller_->DisplayErrorMessageForField(field_, displayed_message);
333 return is_required_valid;
315 } 334 }
316 335
317 } // namespace payments 336 } // namespace payments
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698