Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Shipping labels] Locally validate the address fields and display validation errors #14950

Merged
merged 8 commits into from
Jan 23, 2025

Conversation

rachelmcr
Copy link
Contributor

@rachelmcr rachelmcr commented Jan 22, 2025

Closes: #14943
⚠️ Depends on #14949 ⚠️

Description

This adds the address validation behavior and UI to the Woo Shipping flow:

  1. When a merchant opens the address form, we will immediately validate the address form and show any errors for invalid fields.
  2. When a merchant types in any input fields, we will wait some seconds after the typing stops and perform a validation.
  3. If the value of an input field is not valid, we will display an error.
  4. When a merchant starts typing again on an input field with an error, we will clear the error and wait for the merchant to stop typing and validate the input as in step 2.
  5. When we change focus from one input field to another, we will validate the value of the input field that lost the focus.

Changes

  • We immediately validate all fields in the address when WooShippingEditAddressViewModel inits.
  • We add a debounce before validating new values for WooShippingAddressField, and when cross-validating the name and shipping fields. This allows us to delay validation while a merchant is typing.
  • We add a WooShippingAddressField.clearError() method and use it to clear any error when new text is being entered in an address text field.
  • When observing the company and name fields, we immediately clear both fields when one changes and (after a delay) re-validate them.
  • In the view, we add the UI to display the error message for a field. We also observe changes to the focused field and validate the previous field when it changes.

Testing information

  1. Ensure the latest production version of WooCommerce Shipping (Version 1.3.2) is installed, activated, and set up on your store.
  2. Create or open an order with at least one physical product and the processing status.
  3. Tap "Create Shipping Label" in order details.
  4. Open the "Shipment details" bottom sheet.
  5. Tap the "Ship from" origin address.
  6. Tap the edit (pencil) icon on one of the origin addresses.
  7. In the edit address sheet, confirm the address is validated as expected when the sheet opens.
  8. Erase the text from a required field, wait a second, and confirm the expected validation error appears.
  9. Start typing in the same field and confirm the validation error immediately disappears.
  10. Erase the text from a required field, change the focus to a new field, and confirm the previous field is immediately validated.

Confirm that at each step the status label and button at the bottom of the sheet reflect the current validation status.

Screenshots

Simulator.Screen.Recording.-.iPhone.16.Pro.-.2025-01-22.at.20.34.52.mp4

  • I have considered if this change warrants user-facing release notes and have added them to RELEASE-NOTES.txt if necessary.

Reviewer (or Author, in the case of optional code reviews):

Please make sure these conditions are met before approving the PR, or request changes if the PR needs improvement:

  • The PR is small and has a clear, single focus, or a valid explanation is provided in the description. If needed, please request to split it into smaller PRs.
  • Ensure Adequate Unit Test Coverage: The changes are reasonably covered by unit tests or an explanation is provided in the PR description.
  • Manual Testing: The author listed all the tests they ran, including smoke tests when needed (e.g., for refactorings). The reviewer confirmed that the PR works as expected on all devices (phone/tablet) and no regressions are added.

@rachelmcr rachelmcr added the feature: shipping labels Related to creating, ordering, or printing shipping labels. label Jan 22, 2025
@rachelmcr rachelmcr added this to the 21.5 milestone Jan 22, 2025
@rachelmcr rachelmcr marked this pull request as ready for review January 22, 2025 20:38
@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Jan 22, 2025

WooCommerce iOS📲 You can test the changes from this Pull Request in WooCommerce iOS by scanning the QR code below to install the corresponding build.

App NameWooCommerce iOS WooCommerce iOS
Build Numberpr14950-0f07e85
Version21.4
Bundle IDcom.automattic.alpha.woocommerce
Commit0f07e85
App Center BuildWooCommerce - Prototype Builds #12665
Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed.

Copy link
Contributor

@toupper toupper left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! The validation delay looks great 🚢 :shipit:

Base automatically changed from issue/13781-address-field-type to trunk January 23, 2025 10:07
@dangermattic
Copy link
Collaborator

1 Warning
⚠️ This PR is assigned to the milestone 21.5. This milestone is due in less than 2 days.
Please make sure to get it merged by then or assign it to a milestone with a later deadline.

Generated by 🚫 Danger

@rachelmcr rachelmcr enabled auto-merge January 23, 2025 10:22
@rachelmcr rachelmcr merged commit 9f96073 into trunk Jan 23, 2025
11 of 12 checks passed
@rachelmcr rachelmcr deleted the issue/14943-local-validation-behavior branch January 23, 2025 10:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature: shipping labels Related to creating, ordering, or printing shipping labels.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Shipping labels] Add local validation for address fields
4 participants