-
Notifications
You must be signed in to change notification settings - Fork 219
Add revalidateDependencies
to ValidatedTextInput
#9611
Conversation
The release ZIP for this PR is accessible via:
Script Dependencies ReportThe
This comment was automatically generated by the TypeScript Errors Report
assets/js/blocks/product-collection/edit.tsx
assets/js/blocks/product-top-rated/block.js assets/js/blocks/product-top-rated/index.js packages/checkout/components/text-input/test/validated-text-input.tsx |
Size Change: +578 B (0%) Total Size: 1.09 MB
ℹ️ View Unchanged
|
This check of previous and current value woocommerce-blocks/packages/checkout/components/text-input/validated-text-input.tsx Line 102 in 37c518c
I wonder if there isn't another way of fixing the Coupon code instead of introducing this new field in the ValidatedTextInput API. |
Thanks for the comment! Maybe I'm missing something but I don't see how the check for I believe this new prop is required because we want to revalidate something based on a factor external to the input field. The I actually moved I have updated the testing instructions and PR body. |
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.
Thank you for working on this PR, @opr! LGTM! 👍
I don't understand this question :)
#9377 actually reveals that we need to revalidate if the So I was proposing to fix this issue with another approach, by removing the same value check. I am curious about what performance benefits we gain for skipping validation for fields that have the same value and if it's worth it to include another level of logic in our API. Later edit: If we need to re-trigger validation it should be done at form level, not at a specific field's level. This is an API we can also offer to extensions who'd want to retrigger validation after a certain action. |
closed in favour of a more general approach - issue to track this more general approach |
This is based on
fix/address-pushing
and includes changes from #9606.This PR introduces a new property on
ValidatedTextInput
calledrevalidateDependencies
which is intended to work the same asuseEffect
's dependencies array. This prop will be an array of variables. When one of the variables changes, it will callvalidateInput
again.I added an object in
address-form.tsx
which is keyed by existing fields, and the values are arrays of dependencies that should cause the field to revalidated. When rendering a field, the object is checked and if there's an entry for that field, the value is passed toValidateInput
'srevalidateDependencies
prop. The only items in there now are:postcode: [ country ]
which means that when rendering the postcode field, changing the country will cause it to revalidate. (The country is derived from thewc/store/cart
data store in theuseSelect
above).Finally, I moved the
if ( previousValue === inputObject.value ) {
check to theonBlur
function ofValidatedTextInput
this is so that when the coupon code shows an error, it does not clear when blurring the field.Fixes #9591
Testing
Automated Tests
User Facing Testing
L1 0BP
as the Postcode.8200-294
into the postcode box and check out successfully.WooCommerce Visibility
Performance Impact
Changelog