Skip to content

AddressForm container

The AddressForm container is a standalone component designed for creating and editing customer addresses. This container enables merchants to build a custom user experience around address management while leveraging a pre-built form that minimizes development effort. The form integrates seamlessly with the Adobe Commerce backend environment, providing flexible configuration of address attributes, validation, labels, attribute sorting, and more.

The Addresses container also uses this container.

The following image illustrates a sample AddressForm container:

AddressForm container

AddressForm container

Configurations

The AddressForm container provides the following configuration options:

OptionsTypeReq?Description
hideActionFormButtonsbooleanNoControls the visibility of action buttons at the form's bottom. Useful for custom integrations where form submission is managed externally.
formNamestringNoSets the "name" attribute for the form. Defaults to "addressesForm" if not provided. Useful for custom integrations.
showFormLoaderbooleanNoDetermines if a shimmer loader displays instead of the form. Can be used to manage the form’s loading state externally.
showSaveCheckBoxbooleanNoControls visibility of the "Save in address book" checkbox. Useful for implementations where customers can choose to save the address, with form submission managed externally. Enabling this checkbox hides the action buttons automatically (equivalent to setting "hideActionFormButtons" to "true".)
saveCheckBoxValuebooleanNoSets the initial value of the "Save in address book" checkbox.
forwardFormRefHTMLInputElementNoProvides a reference to the form’s DOM element. Useful for custom integrations. This ref also grants access to the "handleValidationSubmit" method to validate form data.
addressFormIdstringNoPasses an address ID when editing an existing address. Used to identify the address to update in Adobe Commerce.
classNamestringNoAllows custom CSS classes to be applied to the form.
addressesFormTitlestringNoControls visibility of the address form title.
inputsDefaultValueSetCustomerAddressesModelNoAllows a set of default values for form inputs.
shippingCheckBoxValuebooleanNoSets the initial value of the "Set as default shipping address" checkbox.
billingCheckBoxValuebooleanNoSets the initial value of the "Set as default billing address" checkbox.
showShippingCheckBoxbooleanNoControls visibility of the "Set as default shipping address" checkbox. The checkbox remains in the form even if hidden, allowing shippingCheckBoxValue to set its value.
showBillingCheckBoxbooleanNoControls visibility of the "Set as default billing address" checkbox. As with the shipping checkbox, it remains present even if hidden.
isOpenbooleanNoControls the form's visibility.
onSubmitfunctionNoAllows a custom submit handler to override the default form submission behavior.
slots.AddressFormActionsAddressFormActionsContextNoProvides an option to override the call-to-action buttons for the address form.
slots.AddressFormInputsAddressFormInputsContextNoAllows additional custom inputs or HTML elements at the form’s bottom.
slots[`AddressFormInput_${attribute.code}`]slotNoAllows overriding input used for a particular form field. Example slot names: “AddressFormInput_firstname”, “AddressFormInput_street”.
onCloseBtnClickfunctionNoProvides an option to pass a callback to close the form, useful for custom implementations where the form appears in a modal and should close upon successful submission.
onSuccessfunctionNoCallback executed upon successful form submission.
onErrorfunctionNoCallback executed if an error occurs during submission. Receives the error as a parameter.
onChangefunctionNoCallback executed on each form change, receiving form data as a parameter. Useful for custom integrations.

Examples

HTMLInputElement usage sample:

const formRef = { current: null };
provider.render(AddressForm, {
forwardFormRef: formRef,
})(containerWrapper);
const isFormValid = formRef.current.handleValidationSubmit();
const formData = inputRef.current.formData;
return {
handleValidationSubmit,
formData: normalizeGetAddressData(modifyFormRef, true),
isDataValid,
};

isDataValid is a boolean value that indicates whether the form has been validated without an explicit submit action.

inputsDefaultValueSet sample payload:

inputsDefaultValueSet: {
city: 'City',
company: '',
countryCode: 'AR',
region: {
regionCode: 'AR-H',
regionId: 1579,
},
telephone: '123456789',
vatId: '999',
postcode: '12345',
street: 'Street One',
streetMultiline_2: 'Street Two',
}

Example

The following example renders the AddressForm container with custom configurations:

provider.render(AddressForm, {
addressesFormTitle: 'Address form title',
addressId: '',
isOpen: true,
shippingCheckBoxValue: true,
billingCheckBoxValue: true,
showShippingCheckBox: true,
showBillingCheckBox: true,
onChange: (values, inputValue) => {
console.log('allValues', values);
console.log('inputValue', inputValue);
},
onSuccess: () => {
console.log('onSuccess');
},
onError: () => {
console.log('onError');
},
})(containerWrapper);