2

I'm customizing customer address tab in Admin Panel. Here is my code. It's reading my files but 'Add New Addresses' button is not responding.

my code is:

app/code/Learning/Helloworld/view/adminhtml/requirejs-config.js

/**
 * Copyright © 2015 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */

var config = {
    map: {
        '*': {
            'Magento_Ui/js/form/components/collection':'Learning_Helloworld/js/form/components/collection'
        }
    }
};

app/code/Learning/Helloworld/view/adminhtml/web/js/form/components/collection.js

/**
 * Copyright © 2015 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */
define([
    'underscore',
    'mageUtils',
    'uiRegistry',
    'uiComponent',
    'uiLayout',
    'Magento_Ui/js/modal/confirm'
], function (_, utils, registry, Component, layout, confirm) {
    'use strict';

    var childTemplate = {
        parent: '${ $.$data.name }',
        name: '${ $.$data.childIndex }',
        dataScope: '${ $.name }',
        nodeTemplate: '${ $.$data.name }.${ $.$data.itemTemplate }'
    };

    return Component.extend({
        defaults: {
            lastIndex: 0,
            template: 'Learning_Helloworld/form/components/collection'
        },
..........................
    });
});

app/code/Learning/Helloworld/view/adminhtml/web/template/form/components/collection.html

<!--
/**
 * Copyright © 2015 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<div class="ui-tabs">
    <ul class="address-list ui-tabs-nav">
        <h1>Magento 2</h1>
        <!-- ko foreach: { data: element.elems, as: 'element' } -->
        <li class="address-list-item" data-bind="css: { 'ui-state-active': element.active }, click: activate">
            <div class="address-list-item-actions">
                <button class="action-delete" type="button" data-bind="click: $parent.removeAddress.bind($parent, element)">
                    <span data-bind="text: $parent.removeLabel"></span>
                </button>
            </div>
            <!-- ko template: previewTpl --><!-- /ko -->
            <div data-bind="foreach: { data:  element.getRegion('head'), as: 'element' }">
                <!-- ko template: element.getTemplate() --><!-- /ko -->
            </div>
        </li>
        <!-- /ko -->

        <li class="address-list-actions last">
            <button data-bind="click: element.addChild" type="button" class="scalable add">
                <span data-bind="text: element.addLabel"></span>
            </button>
        </li>
    </ul>
    <!-- ko foreach: { data: element.elems, as: 'element' } -->
    <div class="address-item-edit" data-bind="visible: element.active">
        <div class="address-item-edit-content">
            <fieldset class="admin__fieldset">
                <legend class="admin__legend">
                    <span data-bind="text: $parent.label"></span>
                </legend>
                <br>
                <!-- ko foreach: { data: element.getRegion('body'), as: 'element' } -->
                <!-- ko template: element.getTemplate() --><!-- /ko -->
                <!-- /ko -->
            </fieldset>
        </div>
    </div>
    <!-- /ko -->
</div>

After I have ran below commands

php bin/magento cache:clean

php bin/magento cache:flush

php bin/magento setup:static-content:deploy

'Add New Addresses' button is not responding in 'Addresses' tab. Where went wrong?

1 Answer 1

2

try the below code

app/code/Learning/Helloworld/view/base/requirejs-config.js

/**
 * Copyright © 2015 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */

var config = {
    map: {
        '*': {
            'Magento_Ui/js/form/components/collection':'Learning_Helloworld/js/form/components/collection'
        }
    }
};

app/code/Learning/Helloworld/view/base/web/js/form/components/collection.js

/**
 * Copyright © 2015 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */
define([
    'underscore',
    'mageUtils',
    'uiRegistry',
    'uiComponent',
    'uiLayout',
    'Magento_Ui/js/modal/confirm'
], function (_, utils, registry, Component, layout, confirm) {
    'use strict';

    var childTemplate = {
        parent: '${ $.$data.name }',
        name: '${ $.$data.childIndex }',
        dataScope: '${ $.name }',
        nodeTemplate: '${ $.$data.name }.${ $.$data.itemTemplate }'
    };

    return Component.extend({
        defaults: {
            lastIndex: 0,
            template: 'Learning_Helloworld/form/components/collection'
        },
..........................
    });
});

app/code/Learning/Helloworld/view/base/web/template/form/components/collection.html

<!--
/**
 * Copyright © 2015 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<div class="ui-tabs">
    <ul class="address-list ui-tabs-nav">
        <h1>Magento 2</h1>
        <!-- ko foreach: { data: element.elems, as: 'element' } -->
        <li class="address-list-item" data-bind="css: { 'ui-state-active': element.active }, click: activate">
            <div class="address-list-item-actions">
                <button class="action-delete" type="button" data-bind="click: $parent.removeAddress.bind($parent, element)">
                    <span data-bind="text: $parent.removeLabel"></span>
                </button>
            </div>
            <!-- ko template: previewTpl --><!-- /ko -->
            <div data-bind="foreach: { data:  element.getRegion('head'), as: 'element' }">
                <!-- ko template: element.getTemplate() --><!-- /ko -->
            </div>
        </li>
        <!-- /ko -->

        <li class="address-list-actions last">
            <button data-bind="click: element.addChild" type="button" class="scalable add">
                <span data-bind="text: element.addLabel"></span>
            </button>
        </li>
    </ul>
    <!-- ko foreach: { data: element.elems, as: 'element' } -->
    <div class="address-item-edit" data-bind="visible: element.active">
        <div class="address-item-edit-content">
            <fieldset class="admin__fieldset">
                <legend class="admin__legend">
                    <span data-bind="text: $parent.label"></span>
                </legend>
                <br>
                <!-- ko foreach: { data: element.getRegion('body'), as: 'element' } -->
                <!-- ko template: element.getTemplate() --><!-- /ko -->
                <!-- /ko -->
            </fieldset>
        </div>
    </div>
    <!-- /ko -->
</div>

after that execute the below commands in CLI

php bin/magento cache:clean

php bin/magento cache:flush

php bin/magento setup:static-content:deploy

Please let me know if it is not working.

happy coding!!!!!!.

4
  • I will back after I tried Commented Apr 4, 2016 at 5:16
  • not showing my content. Commented Apr 4, 2016 at 5:25
  • @ManojKumar, see updated my answer.
    – Bojjaiah
    Commented Apr 4, 2016 at 5:26
  • So.. basically you changed the adminhtml folder to base folder, right? Commented Jan 22, 2021 at 17:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.