cancel
Showing results for 
Search instead for 
Did you mean: 

How to add a js code to account information tab customer of adminhtml part?

SOLVED
   Did you know you can see the translated content as per your choice?

Translation is in progress. Please check again after few minutes.

How to add a js code to account information tab customer of adminhtml part?

I added custom attributes for customer which are combo boxes and it is good.

I want change list of combo box 2(Rights), when I select an option from combo box 1(Role).

I added a javascript code as below but it doesn't catch event.

I guess I put js codes in a wrong position.  Please tell me where is the correct position.

 

VENDOR/MODULE/view/adminhtml/layout/customer_index_edit.xml

<?xml version="1.0"?>
<!--
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="admin-2columns-left"
      xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceContainer name="content">
            <block class="Shooga\DealerAccess\Block\DealerAccess" template="Shooga_DealerAccess::js.phtml" after="customer_form"/>
        </referenceContainer>
    </body>
</page>
 
VENDOR/MODULE/view/adminhtml/templates/js.phtml
<script type="text/javascript">
    require([
        'jquery'
    ], function($){
        $(document).ready(function(){
            alert('Yes.. It works..!!!');
            $('select[name="customer[role]"').on('change', function() {
                alert('Select');
            });
        });
    });
</script>
Capture.PNG
1 ACCEPTED SOLUTION

Accepted Solutions

Re: How to add a js code to account information tab customer of adminhtml part?

I soved the problem.

I used $(document).ajaxComplete instead of $(document).ready.

<script type="text/javascript">
    require(['jquery', 'domReady!'], function($) {
        'use strict';
        $(document).ajaxComplete(function( event, xhr, settings ) {
            $('select[name="customer[role]"').on('change', function() {
                alert('ds');
            });
        });
    });
</script>

View solution in original post

1 REPLY 1

Re: How to add a js code to account information tab customer of adminhtml part?

I soved the problem.

I used $(document).ajaxComplete instead of $(document).ready.

<script type="text/javascript">
    require(['jquery', 'domReady!'], function($) {
        'use strict';
        $(document).ajaxComplete(function( event, xhr, settings ) {
            $('select[name="customer[role]"').on('change', function() {
                alert('ds');
            });
        });
    });
</script>