Skip to content

Commit

Permalink
Fixed undefined format function when calling one of the built in
Browse files Browse the repository at this point in the history
validators form within a method validator. Fixes #98 and #111
  • Loading branch information
thedersen committed Oct 16, 2013
1 parent 2442aa3 commit 3861c76
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 2 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -819,6 +819,10 @@ Basic behaviour:
## Release notes
#### Master
* Fixed undefined format function when calling one of the built in validators form within a method validator. Fixes #98
#### v0.8.2 [commits](https://github.com/thedersen/backbone.validation/compare/v0.8.1...v0.8.2)
* `preValidate` now accepts a hash of attributes in addition to a key/value
Expand Down
2 changes: 1 addition & 1 deletion dist/backbone-validation-amd-min.js

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions dist/backbone-validation-amd.js
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,10 @@
};
}());

_.each(defaultValidators, function(validator, key){
defaultValidators[key] = _.bind(defaultValidators[key], _.extend({}, formatFunctions, defaultValidators));
});

return Validation;
}(_));
return Backbone.Validation;
Expand Down
2 changes: 1 addition & 1 deletion dist/backbone-validation-min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions dist/backbone-validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -619,5 +619,9 @@ Backbone.Validation = (function(_){
};
}());

_.each(defaultValidators, function(validator, key){
defaultValidators[key] = _.bind(defaultValidators[key], _.extend({}, formatFunctions, defaultValidators));
});

return Validation;
}(_));
6 changes: 6 additions & 0 deletions src/backbone-validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -612,5 +612,11 @@ Backbone.Validation = (function(_){
};
}());

// Set the correct context for all validators
// when used form within a method validator
_.each(defaultValidators, function(validator, key){
defaultValidators[key] = _.bind(defaultValidators[key], _.extend({}, formatFunctions, defaultValidators));
});

return Validation;
}(_));
19 changes: 19 additions & 0 deletions tests/validators/method.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,23 @@ buster.testCase("method validator short hand syntax", {

assert.equals({attr:'attr', name:'name', age:1}, this.computed);
}
});

buster.testCase("method validator using other built in validator(s)", {
setUp: function() {
var Model = Backbone.Model.extend({
validation: {
name: function(val, attr, computed) {
return Backbone.Validation.validators.length(val, attr, 4, this);
}
}
});

_.extend(Model.prototype, Backbone.Validation.mixin);
this.model = new Model();
},

"it should format the error message returned from the built in validator": function(){
assert.equals('Name must be 4 characters', this.model.preValidate('name', ''));
}
});

0 comments on commit 3861c76

Please sign in to comment.