-
Notifications
You must be signed in to change notification settings - Fork 219
Add validation to local pickup fields #8007
Add validation to local pickup fields #8007
Conversation
const form = | ||
formRef?.current as unknown as HTMLFormElement; | ||
if ( form.reportValidity() ) { | ||
onSave( values ); | ||
onClose(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Button here is outside the form, so we use the ref instead of event.target.form
onClick={ ( | ||
event: React.MouseEvent< HTMLButtonElement, MouseEvent > | ||
) => { | ||
const target = event.target as HTMLButtonElement; | ||
if ( target?.form?.reportValidity() ) { | ||
save(); | ||
} | ||
} } | ||
type="submit" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is all that's needed to show errors, reportValidity
will return true once all fields are valid.
The release ZIP for this PR is accessible via:
|
TypeScript Errors ReportFiles with errors: 444
assets/js/base/components/cart-checkout/shipping-rates-control-package/package-rates.tsx
assets/js/base/components/cart-checkout/shipping-rates-control/types.ts assets/js/base/components/cart-checkout/totals/shipping/shipping-address.tsx assets/js/base/components/reviews/review-list-item/index.js assets/js/base/components/reviews/review-list/index.js assets/js/base/components/reviews/review-sort-select/index.js assets/js/base/context/hooks/cart/use-store-cart-coupons.ts assets/js/base/context/hooks/use-checkout-notices.js assets/js/base/context/providers/cart-checkout/checkout-processor.js assets/js/base/context/providers/store-snackbar-notices/components/snackbar-notices-container.js assets/js/base/utils/errors.js assets/js/blocks/cart-checkout-shared/payment-methods/payment-method-error-boundary.js assets/js/blocks/cart/block.js assets/js/blocks/checkout/block.tsx assets/js/blocks/checkout/inner-blocks/checkout-pickup-options-block/index.tsx assets/js/blocks/checkout/inner-blocks/checkout-shipping-method-block/block.tsx assets/js/blocks/checkout/inner-blocks/checkout-shipping-method-block/edit.tsx assets/js/blocks/checkout/inner-blocks/checkout-shipping-method-block/index.tsx assets/js/data/cart/controls.js assets/js/data/cart/test/resolvers.js assets/js/extensions/payment-methods/cod/index.js assets/js/extensions/shipping-methods/pickup-location/edit-location/form.tsx assets/js/extensions/shipping-methods/pickup-location/edit-location/state-control.tsx assets/js/extensions/shipping-methods/pickup-location/save.tsx assets/js/extensions/shipping-methods/pickup-location/settings-context.tsx assets/js/extensions/shipping-methods/shared-components/sortable-table/index.tsx packages/checkout/components/store-notice/index.tsx packages/checkout/components/store-notices-container/index.tsx |
Size Change: +127 B (0%) Total Size: 1.06 MB
ℹ️ View Unchanged
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great, test good and code looks fine. Ship it.
* add form validation for admin screen * add types * add validation to fields * restore form ref
* add form validation for admin screen * add types * add validation to fields * restore form ref
This adds simple validation to form fields to prevent empty values from being persisted. It adds it to the modal, the general form, and the editor.
Fixes #7988
Fixes #7989
Fixes #7991
Screenshots
Testing