The shipping and billing address forms in our checkout are based loosely on the ones from the example templates.

With the example templates, if you checkout as a logged in user and that user has previously saved addresses, the 'new address' form fields get pre-populated with the data from the user's first saved address.

If I output cart.shippingAddress, I can see that the user's first saved address has already been automatically assigned to the cart before the user has actually selected/entered an address. So I presume that's why this is happening. And I don't necessarily have a problem with a saved address being automatically selected. It's just the fact that it is pre-populating the new address form fields that is the problem.

The value attribute on the form fields looks something like this:

value="{{ cart.shippingAddress ? cart.shippingAddress.firstName : '' }}"

So obviously I can just remove the value attribute altogether to solve this problem. But then the field would not be repopulated in the event of an error in the submitting of the form, meaning that the user would need to re-enter all their details - not ideal.

So is there any way to prevent the form fields from being pre-populated in this way?


  • You can modify the twig object value in the input to only show when there is an error in the form by using cart.hasErrors(). In your case your code would look like value="{{ cart.hasErrors() ? cart.firstName : '' }}" – Dale Ramirez yesterday

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.