3

Firstly, yes I'm in developer mode - and yes i've got the caché turned off and flushing it ( i've also deleted pub/static a fair few times ).

My issue:

I have an extension which adds a page to the admin area of the site on this page Im using require js to call in plugins to do things. Here is my requirejs file:

var config = {
  map: {
    '*': {
        nestable:  'Vender_Default/js/jquery.nestable.min'
    }
  }
};

Which is inside of the following file:

vender/default/view/adminhtml/web/requirejs-config.js

and then in the page I'm doing the following:

require([
        'jquery',
        'nestable'
    ], function($, nestable) {
        $('#nestable').nestable({
                    group: 1,
                    maxDepth: 15
                }).on('change', updateOutput);
        });

Which i thought was correct, however i get the following errors:

Cannot read property 'fn' of undefined at jquery.nestable.min.js:1

and

TypeError: $(...).nestable is not a function

Which clearly its not now, because of the first error. Does anyone have any idea why I am getting this issue? I can't seem to get my head around why its not working. And most other questions on here don't seem to be the same issue.

** Have changed jQuery to $ and still receiving the error.

Thanks

2

2 Answers 2

1

You need to do as below, need to change jQuery to $ as argument,

require([
    'jquery',
    'nestable'
], function($, nestable) {
        $('#nestable').nestable({
            group: 1,
            maxDepth: 15
        }).on('change', updateOutput);
});
3
  • Yes, i tried this as i'd seen it in other places. However Im still getting the error - even after the change.
    – andy jones
    Commented Jan 31, 2018 at 8:51
  • did you try to run upgrade and deploy command Commented Jan 31, 2018 at 8:53
  • Shouldn't need to deploy as currently in dev mode. However i will run the upgrade command to see.
    – andy jones
    Commented Jan 31, 2018 at 8:57
0

Okay, Thanks for @Rakesh-jesadiya for the answer, as i was doing that part wrong!! And have changed it.

But i've found out that doing the following to the nestable.min.js file fixes it:

define([
    'jquery'
], function($){
    // do nestable jquery plugin here.
});

Looks like the plugin doesn't know what jQuery is, and defining the jquery around the plugin worked.

Can anyone explain this?

I assumed requiring jquery before the plugin, in the file would do this? Its only taken me... 30+ minutes to find the answer >_<

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.