Permalink
Browse files

Labelformatter set to 'label' no longer crashes when no labels attrib…

…ute is present on the model. Fixes #73
  • Loading branch information...
1 parent 5ee680f commit ca2ec79bd334f7d2d085fa90852be15b865144a0 @thedersen committed Nov 20, 2012
Showing with 16 additions and 1 deletion.
  1. +1 −1 src/backbone-validation.js
  2. +15 −0 tests/labelFormatter.js
View
2 src/backbone-validation.js
@@ -373,7 +373,7 @@ Backbone.Validation = (function(_){
// }
// });
label: function(attrName, model) {
- return model.labels[attrName] || defaultLabelFormatters.sentenceCase(attrName, model);
+ return (model.labels && model.labels[attrName]) || defaultLabelFormatters.sentenceCase(attrName, model);
}
};
View
15 tests/labelFormatter.js
@@ -52,6 +52,21 @@ buster.testCase('Label formatters', {
"returns sentence cased name when label is not found": function(){
assert.equals('Some attribute is required', this.model.preValidate('some_attribute', ''));
+ },
+
+ "returns sentence cased name when label attribute is not defined": function(){
+ var Model = Backbone.Model.extend({
+ validation: {
+ someAttribute: {
+ required: true
+ }
+ }
+ });
+
+ var model = new Model();
+ _.extend(model, Backbone.Validation.mixin);
+
+ assert.equals('Some attribute is required', model.preValidate('someAttribute', ''));
}
},

0 comments on commit ca2ec79

Please sign in to comment.