I have created admin form using uiComponent. I have called phtml file using <htmlContent name="html_content"> in xml file. I tired to call custom.js using below code but its not working.

<script type="text/x-magento-init">
        "*": {
            "Namespace_Module/js/custom": {
                "Data": <?= /* @noEscape */ json_encode($data, JSON_HEX_QUOT) ?>,
                "isSortable":  <?= (int)(!$block->getReadOnly()) ?>,
                "isReadOnly": <?= (int)$block->getReadOnly() ?>

This code is working fine if I call it using simple block method without uiComponent.

Please let me know how can I use my custom js file with uiComponent form.

  • you have try with require ["jQuery","jQuery/ui"]] – Rutvee Sojitra Sep 27 '18 at 12:40
  • No can you please provide code for the same. – poojan sharma Sep 27 '18 at 12:52

You can add dependencies.

define(['your/module/path/or/alias'],function(module){  module.useMyMethod() });

reference: https://devdocs.magento.com/guides/v2.0/javascript-dev-guide/javascript/js-resources.html

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.