Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Changed api, use form.complete(function(){}) instead of form.onComple…

…te = function(){}
  • Loading branch information...
commit 8a1f77c4c2042f117e8566ec0fe74256bb1d772a 1 parent 0f0ce18
@tj tj authored
Showing with 13 additions and 12 deletions.
  1. +2 −2 Readme.md
  2. +9 −8 index.js
  3. +2 −2 test/form.test.js
View
4 Readme.md
@@ -24,13 +24,13 @@ via npm:
// Do something when parsing is finished
// and respond, or respond immediately
// and work with the files.
- req.form.onComplete = function(err, fields, files){
+ req.form.complete(function(err, fields, files){
res.writeHead(200, {});
if (err) res.write(JSON.stringify(err.message));
res.write(JSON.stringify(fields));
res.write(JSON.stringify(files));
res.end();
- };
+ });
// Regular request, pass to next middleware
} else {
next();
View
17 index.js
@@ -32,13 +32,13 @@ var utils = require('connect/utils'),
* // Do something when parsing is finished
* // and respond, or respond immediately
* // and work with the files.
- * req.form.onComplete = function(err, fields, files){
+ * req.form.complete(function(err, fields, files){
* res.writeHead(200, {});
* if (err) res.write(JSON.stringify(err.message));
* res.write(JSON.stringify(fields));
* res.write(JSON.stringify(files));
* res.end();
- * };
+ * });
* // Regular request, pass to next middleware
* } else {
* next();
@@ -55,14 +55,15 @@ module.exports = function(options){
options = options || {};
return function(req, res, next){
if (formRequest(req)) {
- var form = req.form = new formidable.IncomingForm;
+ var callback = function(){},
+ form = req.form = new formidable.IncomingForm;
utils.merge(form, options);
- form.onComplete = function(){};
- next();
- form.parse(req, form.onComplete);
- } else {
- next();
+ form.complete = function(fn){ callback = fn; };
+ form.parse(req, function(){
+ callback.apply(this, arguments);
+ });
}
+ next();
};
};
View
4 test/form.test.js
@@ -12,13 +12,13 @@ var server = connect.createServer(
form(),
function(req, res, next){
if (req.form) {
- req.form.onComplete = function(err, fields, files){
+ req.form.complete(function(err, fields, files){
res.writeHead(200, {});
if (err) res.write(JSON.stringify(err.message));
res.write(JSON.stringify(fields));
res.write(JSON.stringify(files));
res.end();
- };
+ });
} else {
next();
}
Please sign in to comment.
Something went wrong with that request. Please try again.