diff --git a/packages/authenticator/amplify_authenticator/lib/src/mixins/authenticator_phone_field.dart b/packages/authenticator/amplify_authenticator/lib/src/mixins/authenticator_phone_field.dart index be4a31ff62..a03679c879 100644 --- a/packages/authenticator/amplify_authenticator/lib/src/mixins/authenticator_phone_field.dart +++ b/packages/authenticator/amplify_authenticator/lib/src/mixins/authenticator_phone_field.dart @@ -47,8 +47,7 @@ mixin AuthenticatorPhoneFieldMixin get validator { switch (selectedUsernameType) { @@ -192,7 +183,7 @@ mixin AuthenticatorUsernameField validatePhoneNumber({ InputResolverKey.phoneNumberEmpty, ); } - final formattedNumber = phoneNumber.trim(); - if (!phoneNumberRegex.hasMatch(formattedNumber)) { + phoneNumber = phoneNumber.trim(); + if (!phoneNumberRegex.hasMatch(phoneNumber)) { return inputResolver.resolve(context, InputResolverKey.phoneNumberFormat); } return null; diff --git a/packages/authenticator/amplify_authenticator/lib/src/widgets/form_fields/confirm_sign_in_form_field.dart b/packages/authenticator/amplify_authenticator/lib/src/widgets/form_fields/confirm_sign_in_form_field.dart index 1407e7e153..409faffa3f 100644 --- a/packages/authenticator/amplify_authenticator/lib/src/widgets/form_fields/confirm_sign_in_form_field.dart +++ b/packages/authenticator/amplify_authenticator/lib/src/widgets/form_fields/confirm_sign_in_form_field.dart @@ -559,7 +559,7 @@ class _ConfirmSignInPhoneFieldState extends _ConfirmSignInTextFieldState @override FormFieldValidator get validator { return (phoneNumber) { - phoneNumber = displayPhoneNumber(phoneNumber); + phoneNumber = formatPhoneNumber(phoneNumber); return validatePhoneNumber( inputResolver: stringResolver.inputs, context: context, diff --git a/packages/authenticator/amplify_authenticator/lib/src/widgets/form_fields/phone_number_field.dart b/packages/authenticator/amplify_authenticator/lib/src/widgets/form_fields/phone_number_field.dart index c9dac65ebd..b3cb32a3bd 100644 --- a/packages/authenticator/amplify_authenticator/lib/src/widgets/form_fields/phone_number_field.dart +++ b/packages/authenticator/amplify_authenticator/lib/src/widgets/form_fields/phone_number_field.dart @@ -86,12 +86,11 @@ class _AuthenticatorPhoneFieldState @override FormFieldValidator get validator { return (String? phoneNumber) { + phoneNumber = formatPhoneNumber(phoneNumber); final validator = widget.validator; if (validator != null) { - phoneNumber = formatPhoneNumber(phoneNumber); return validator(phoneNumber); } - phoneNumber = displayPhoneNumber(phoneNumber); return validatePhoneNumber( inputResolver: stringResolver.inputs, context: context, diff --git a/packages/authenticator/amplify_authenticator/lib/src/widgets/form_fields/sign_up_form_field.dart b/packages/authenticator/amplify_authenticator/lib/src/widgets/form_fields/sign_up_form_field.dart index c365372cb5..94b9e39517 100644 --- a/packages/authenticator/amplify_authenticator/lib/src/widgets/form_fields/sign_up_form_field.dart +++ b/packages/authenticator/amplify_authenticator/lib/src/widgets/form_fields/sign_up_form_field.dart @@ -738,7 +738,7 @@ class _SignUpPhoneFieldState extends _SignUpTextFieldState @override FormFieldValidator get validator { return (phoneNumber) { - phoneNumber = displayPhoneNumber(phoneNumber); + phoneNumber = formatPhoneNumber(phoneNumber); return validatePhoneNumber( inputResolver: stringResolver.inputs, context: context, diff --git a/packages/authenticator/amplify_authenticator/test/sign_up_form_test.dart b/packages/authenticator/amplify_authenticator/test/sign_up_form_test.dart index 683c6d68d3..119bf106b7 100644 --- a/packages/authenticator/amplify_authenticator/test/sign_up_form_test.dart +++ b/packages/authenticator/amplify_authenticator/test/sign_up_form_test.dart @@ -118,44 +118,6 @@ void main() { }, ); - testWidgets( - 'displays message when submitted with empty phone number if the field is required', - (tester) async { - await tester.pumpWidget( - MockAuthenticatorApp( - initialStep: AuthenticatorStep.signUp, - signUpForm: SignUpForm.custom( - fields: [ - SignUpFormField.username(), - SignUpFormField.phoneNumber(required: true), - SignUpFormField.password(), - ], - ), - ), - ); - await tester.pumpAndSettle(); - - final signUpPage = SignUpPage(tester: tester); - - await signUpPage.submitSignUp(); - - await tester.pumpAndSettle(); - - Finder findPhoneFieldError() => find.descendant( - of: signUpPage.phoneField, - matching: find.text('Phone Number field must not be blank.'), - ); - - expect(findPhoneFieldError(), findsOneWidget); - - await signUpPage.enterPhoneNumber('1235556789'); - - await signUpPage.submitSignUp(); - - expect(findPhoneFieldError(), findsNothing); - }, - ); - testWidgets( 'displays message when submitted with invalid birth date', (tester) async {