3

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() ?>
            }   
        }
    }
</script>

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.

2
  • you have try with require ["jQuery","jQuery/ui"]] Sep 27, 2018 at 12:40
  • No can you please provide code for the same. Sep 27, 2018 at 12:52

1 Answer 1

0

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 and acknowledge you have read our privacy policy.

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