jquery.validation

193 views
Skip to first unread message

SteveG

unread,
Feb 9, 2012, 8:49:53 PM2/9/12
to volojs
What is best approach to converting libraries such as
jquery.validation to be 'AMD/RequireJs' ?

I have a handful of libraries I use that aren't AMD and need to find
out if volojs can handle that or I need to pursue a different path.

Thanks!

James Burke

unread,
Feb 9, 2012, 9:58:47 PM2/9/12
to vol...@googlegroups.com

volo's "amdify" command can do that. You can type "volo help amdify"
to get some help docs on it, but for jQuery plugins that just have a
dependency on jQuery:

volo amdify depends=jquery path/to/jquery.plugin.js

That will add a define() wrapper to the code with a dependency on 'jquery'.

James

Steve Gentile

unread,
Feb 9, 2012, 10:56:36 PM2/9/12
to vol...@googlegroups.com
excellent, thanks for your help!

-- 
Steve Gentile
Sent with Sparrow

shu chen

unread,
Feb 27, 2013, 9:23:11 AM2/27/13
to vol...@googlegroups.com
How did you solve this. I followed James' advice, volo add some lines into my jquery.validation.js 
My commands:
volo amdify depends=jquery ./resources/plugin/jquery-validation-1.9.0/jquery.validate.js 
CONVERTED: ./resources/plugin/jquery-validation-1.9.0/jquery.validate.js: depends: 'jquery'

some new lines were added into js:
//Wrapped in an outer function to preserve global this
(function (root) { var amdExports; define(['jquery'], function () { (function () {

.....




}.call(root));
    return amdExports;
}); }(this));


When I try to load jquery.validation in my js using requireJS with AMD like so:

/*global window, document */
require.config({
paths: {
"jquery": "../thirdParty/jquery-1.8.0.min",
"ajaxUtility": "./ajaxUtility",
"jquery.artDialog": "../../plugin/artDialog4.1.6/jquery.artDialog",
"validate": "../../plugin/jquery-validation-1.9.0/jquery.validate"
},
shim: {
"jquery.artDialog": {
deps: ["jquery"],
exports: "artDialog"
}
}

});


define("messagePage", ["jquery", "ajaxUtility", "dialog", "jqueryTool", "validate", "message"], function ($, ajaxUtility, dialog, jqueryTool, validate, message) {
'use strict';
...
}

but the validate is still undefined.

How to fix this?

James Burke

unread,
Feb 28, 2013, 12:39:26 AM2/28/13
to vol...@googlegroups.com
On Wed, Feb 27, 2013 at 6:23 AM, shu chen <csfre...@gmail.com> wrote:
> define("messagePage", ["jquery", "ajaxUtility", "dialog", "jqueryTool",
> "validate", "message"], function ($, ajaxUtility, dialog, jqueryTool,
> validate, message) {

volo amdify takes an "exports" property to also set what the module
export should be, so that the "validate" argument passed to this
define function would have a value:

https://github.com/volojs/volo/blob/master/commands/amdify/doc.md

I think this should work:

volo amdify depends=jquery exports=$.validate
./resources/plugin/jquery-validation-1.9.0/jquery.validate.js

but I'm not exactly sure what that plugin adds to the global $
variable, so I might have that wrong.

That said, since it is a jquery plugin, it should just be attached to
the $ object, even without doing this exports thing. Usually for
jquery plugins you do not reference them directly but use $ to get to
them.

James
Reply all
Reply to author
Forward
0 new messages