I’m working with the new Checkout UI extensions and trying to get the value(data) from the ZIP input after each keyup event or after the blur event.
I am following this official example but the problem is that api.shippingAddress is undefined at the point of opening the checkout.
This means that the function api.shippingAddress.subscribe is not working.
https://shopify.dev/docs/api/checkout-ui-extensions → JS Tab
import {
extend,
Banner,
} from '@shopify/checkout-ui-extensions';
extend(
'Checkout::DeliveryAddress::RenderBefore',
(root, api) => {
renderApp(root, api);
api.shippingAddress.subscribe(() =>
renderApp(root, api),
);
},
);
function renderApp(root, api) {
const {countryCode} =
api.shippingAddress.current;
// In case of a re-render, remove previous children.
for (const child of root.children) {
root.removeChild(child);
}
if (countryCode !== 'CA') {
const banner = root.createComponent(
Banner,
{},
'Sorry, we can only ship to Canada at this time',
);
root.appendChild(banner);
}
}
Are there other ways of getting the value?
