0

I tried this:

require.config({
    paths: {
        jquery: '../lib/zepto/zepto-1.1.3', 
        "jquery.parsley": '../lib/parsley/parsley-2.0.2'
    },
    shim: {
        'jquery.parsley': ['jquery']   // I also tried without this
    }
});

define(['jquery', 'jquery.parsley'], function( $ ) {
    $("#signup-form").parsley('validate'); // "signup-form" is the form id
});

but I get this error:

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

What am I doing wrong? Could you help me to make it work? Thanks

Frank
  • 2,083
  • 8
  • 34
  • 52
  • You need to include **ALL** your dependencies as parameters in your function. You did only so for jQuery, not parsley. Just change it to: `define(['jquery', 'jquery.parsley'], function( $, parsley ) {` – webketje Jun 21 '14 at 10:58
  • @Tyblitz ok thanks but it does not work. same error! – Frank Jun 21 '14 at 15:50
  • Upon further inspection, (1) You forgot the `#` in the signup-form selector, and (2) it seems the documentation says that jQuery doesn't need a shim to be loaded (it worked perfectly without for me too). Normally this section of the documentation should explain all you need, if you follow it cautiously: http://requirejs.org/docs/api.html#config-shim – webketje Jun 21 '14 at 17:29
  • ok I edited the code and tried, but same thing. It does not recognize the `parsley` function – Frank Jun 21 '14 at 18:53
  • Aha! I think this post may help you out: http://stackoverflow.com/questions/17366073/requirejs-define-vs-require . If this don't work, sorry but I can't come up with anything better – webketje Jun 22 '14 at 09:44

2 Answers2

0

Parsley 2.0.2 does not need a shim because it calls define. See the source:

if (typeof define === 'function' && define.amd) {
  // AMD. Register as an anonymous module depending on jQuery.
  define(['jquery'], factory);
} else {

It calls define, so no shim. You've defined a shim for it. Loading with a shim a module that does not need a shim results in undefined behavior.

Louis
  • 146,715
  • 28
  • 274
  • 320
-1

I had the same problem but I figured out that Parsley depends on Jquery so in your shim configuration you should write:

paths: {
       "jquery" : "../libs/jquery/jquery-1.11.0.min",
       "parsley" : "../libs/parsley/parsley.min",
}

shim: {

       "parsley": {
                    "deps" : ["jquery"],
                    "exports" : "parsley"
      }
}
Androbito
  • 329
  • 1
  • 4
  • 8