1

I want to include custom JavaScript to create new product form.

I already try with below way

  1. Using XML way.

app/code/Namespace/Modulename/view/adminhtml/layout/index_index_add.xml

<head>
    <link src="Namespace_modulename::js/website_validation.js"/>
</head>
  1. Using require-config.js way

app/code/Namespace/Modulename/view/adminhtml/require-config.js

var config = {
   'paths': {
       websitevalidation: 'Namespace_Modulename/js/website_validation'
   }
};

app/code/Namespace/Modulename/view/adminhtml/web/js/website_validation.js

require(['jquery','websitevalidation'],function($){
    $(window).load(function() {
        alert('innn');

    });
});

What i missing or wrong in above code.

Any help would be appreciated. Thanks.

1

Please change your xml file name in 1 way (Using xml way)

app/code/Namespace/Modulename/view/adminhtml/layout/index_index_add.xml

Change layout xml file name to

catalog_product_new.xml

1

Use...

app/code/Namespace/Modulename/view/adminhtml/layout/catalog_product_new.xml

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.