Comparing version 0.1.1 to 0.2.0
@@ -32,4 +32,13 @@ // Generated by CoffeeScript 1.7.1 | ||
Springform.prototype.bind = function(data) { | ||
this.data = data; | ||
Springform.prototype.set = function(key, value) { | ||
var args; | ||
if (typeof key === 'string') { | ||
this[key] = value; | ||
} else { | ||
args = key; | ||
for (key in args) { | ||
value = args[key]; | ||
this[key] = value; | ||
} | ||
} | ||
return this; | ||
@@ -55,3 +64,3 @@ }; | ||
Springform.prototype.validator = function(validator) { | ||
Springform.prototype.addValidator = function(validator) { | ||
this.validators.push(validator); | ||
@@ -91,9 +100,9 @@ return this; | ||
} | ||
if (this.processing) { | ||
if (this.saving) { | ||
return; | ||
} | ||
this.processing = true; | ||
return this.process((function(_this) { | ||
this.saving = true; | ||
return this.save((function(_this) { | ||
return function() { | ||
return _this.processing = false; | ||
return _this.saving = false; | ||
}; | ||
@@ -103,11 +112,6 @@ })(this)); | ||
Springform.prototype.process = function(done) { | ||
Springform.prototype.save = function(done) { | ||
return done(); | ||
}; | ||
Springform.prototype.processor = function(process) { | ||
this.process = process; | ||
return this; | ||
}; | ||
return Springform; | ||
@@ -114,0 +118,0 @@ |
{ | ||
"name": "springform", | ||
"version": "0.1.1", | ||
"version": "0.2.0", | ||
"description": "For cheesecake and full-stack form processing", | ||
@@ -5,0 +5,0 @@ "author": "Good Eggs <open-source@goodeggs.com>", |
@@ -48,3 +48,3 @@ Springform [![NPM version](https://badge.fury.io/js/springform.png)](http://badge.fury.io/js/springform) [![Build Status](https://travis-ci.org/goodeggs/springform.png)](https://travis-ci.org/goodeggs/springform) | ||
functinon (req, res) { | ||
var form = new RobotForm().bind(req.body).validate() | ||
var form = new RobotForm({data: req.body}).validate() | ||
if(form.hasErrors()) { | ||
@@ -63,5 +63,5 @@ res.json(form.errors()) | ||
var robot = {sound: 'beep', color: 'red'}, | ||
form = new Springform() | ||
.bind(robot) | ||
.processor(function (done) { | ||
form = new Springform({ | ||
data: robot, | ||
save: function (done) { | ||
$.ajax({ | ||
@@ -79,2 +79,3 @@ dataType: 'json', | ||
}) | ||
}) | ||
@@ -96,3 +97,3 @@ rivets.bind(formEl, form) | ||
fieldErrors: { | ||
<fieldName>: < ... >, | ||
<fieldName>: < ... >, | ||
<otherFieldName>: < ... > | ||
@@ -128,3 +129,3 @@ } | ||
Validators can by syncronous or asyncronous. | ||
Validators can by syncronous or asyncronous. | ||
@@ -156,3 +157,3 @@ #### Simple | ||
--- | ||
#### bind(data) | ||
#### set('data', {...}) | ||
Chainable sugar to set `form.data`. Feel free to set form.data directly if you don't need chainability. | ||
@@ -166,3 +167,3 @@ | ||
#### validator(validatorFn) | ||
#### addValidator(validatorFn) | ||
Chainable sugar to push a [validator function](#validators) onto `validators` to be run when `validate()` is called. | ||
@@ -174,13 +175,12 @@ | ||
#### submit([event]) | ||
Call `process()` and set the `processing` flag while it's running. Calls `preventDefault()` on the passed in event if used as an event listener. | ||
Call `save()` and set the `saving` flag while it's running. Calls `preventDefault()` on the passed in event if used as an event listener. | ||
#### process(done) | ||
An async function that does the work of submitting the form. Could be an Ajax POST, a model.save(), or something else entirely. Be sure to call `done` if you want to unlock form re-submission. Processors frequently call some combination of `validate()`, `errors({...})`, and `hasErrors()`. Define this function on an instance, on a prototype, or pass it in to `processor()`. | ||
#### save(done) | ||
An async function that does the work of submitting the form. Could be an Ajax POST, a model.save(), or something else entirely. Be sure to call `done` if you want to unlock form re-submission. Save functions frequently call some combination of `validate()`, `errors({...})`, and `hasErrors()`. Define this function on an instance, on a prototype, or pass it in to `set()`. | ||
#### processor(processorFn) | ||
Chainable sugar to set `process`. | ||
#### saving | ||
A boolean flag that's `true` while the form is saving. | ||
#### set('save', saveFn) | ||
Chainable sugar to set `save`. | ||
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
20165
158