Magento – Found 2 elements with non-unique id #billing-new-address-form Magento 2

billing-addressmagento-2.1onepage-checkout

When on the checkout page, I receive the following console error when selecting the shipping method and going to the next-step 'payment'.

[DOM] Found 2 elements with non-unique id #billing-new-address-form:

[DOM] Found 2 elements with non-unique id #billing-save-in-address-book: `

How can I resolve this issue?

Best Answer

This issue is fixed in 2.3-develop branch, it's also backported to 2.2 and going to be released in 2.2.6, I can see it's backported to 2.1 too.

There are 2 places need to change to fix the issue

vendor/magento/module-gift-message/view/frontend/web/template/gift-message-form.html

<!--
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<!-- ko if: isActive() -->
<div class="gift-message">
    <div class="gift-options-title">
        <span data-bind="i18n: 'Gift Message (optional)'"></span>
    </div>
    <div class="gift-options-content">
        <fieldset class="fieldset">
            <div class="field field-to">
                <label data-bind="attr: {for: 'gift-message-whole-to-' + index }" class="label">
                    <span data-bind="i18n: 'To:'"></span>
                </label>
                <div class="control">
                    <input type="text"
                           class="input-text"
                           data-bind="value: getObservable('recipient'), attr: { id: 'gift-message-whole-to-' + index }">
                </div>
            </div>

            <div class="field field-from">
                <label data-bind="attr: {for: 'gift-message-whole-from-' + index }" class="label">
                    <span data-bind="i18n: 'From:'"></span>
                </label>
                <div class="control">
                    <input type="text"
                           class="input-text"
                           data-bind="value: getObservable('sender'), attr: { id: 'gift-message-whole-from-' + index }">
                </div>
            </div>
            <div class="field text">
                <label for="gift-message-whole-message" class="label">
                    <span data-bind="i18n: 'Message:'"></span>
                </label>
                <div class="control">
                    <textarea id="gift-message-whole-message"
                              class="input-text"
                              rows="5" cols="10"
                              data-bind="value: getObservable('message')"></textarea>
                </div>
            </div>
        </fieldset>

    </div>
</div>
<!-- /ko -->
<div class="actions-toolbar">
    <div class="secondary">
        <button type="submit" class="action secondary action-update" data-bind="
                    attr: {title: $t('Update')},
                    click: $data.submitOptions.bind($data)">
            <span data-bind="i18n: 'Update'"></span>
        </button>
        <button class="action action-cancel" data-bind="
                    attr: {title: $t('Cancel')},
                    click: $data.hideFormBlock.bind($data)">
            <span data-bind="i18n: 'Cancel'"></span>
        </button>
    </div>
</div>

vendor/magento/module-checkout/view/frontend/web/template/billing-address/form.html

<!--
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<div class="billing-address-form" data-bind="fadeVisible: isAddressFormVisible">
    <!-- ko foreach: getRegion('before-fields') -->
    <!-- ko template: getTemplate() --><!-- /ko -->
    <!--/ko-->
    <form data-bind="attr: {'data-hasrequired': $t('* Required Fields')}">
        <fieldset
            data-bind="attr: { id:'billing-new-address-form-'+index, value:index}"
            class="billing-new-address-form fieldset address">
            <!-- ko foreach: getRegion('additional-fieldsets') -->
            <!-- ko template: getTemplate() --><!-- /ko -->
            <!--/ko-->
            <!-- ko if: (isCustomerLoggedIn && customerHasAddresses) -->
            <div class="choice field">
                <input type="checkbox" class="checkbox"  data-bind="checked: saveInAddressBook, attr: {id: 'billing-save-in-address-book-' + getCode($parent)}" />
                <label class="label" data-bind="attr: {for: 'billing-save-in-address-book-' + getCode($parent)}" >
                    <span data-bind="i18n: 'Save in address book'"></span>
                </label>
            </div>
            <!-- /ko -->
        </fieldset>
    </form>
</div>

Cheers

Related Topic