1

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?

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!!!!!!.

  • I will back after I tried – Manoj Kumar Apr 4 '16 at 5:16
  • not showing my content. – Manoj Kumar Apr 4 '16 at 5:25
  • @ManojKumar, see updated my answer. – Bojjaiah Apr 4 '16 at 5:26

Your Answer

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

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