10000 Labelformatter set to 'label' no longer crashes when no labels attrib… · thedersen/backbone.validation@ca2ec79 · GitHub
[go: up one dir, main page]

Skip to content

Commit ca2ec79

Browse files
committed
Labelformatter set to 'label' no longer crashes when no labels attribute is present on the model. Fixes #73
1 parent 5ee680f commit ca2ec79

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/backbone-validation.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ Backbone.Validation = (function(_){
373373
// }
374374
// });
375375
label: function(attrName, model) {
376-
return model.labels[attrName] || defaultLabelFormatters.sentenceCase(attrName, model);
376+
return (model.labels && model.labels[attrName]) || defaultLabelFormatters.sentenceCase(attrName, model);
377377
}
378378
};
379379

tests/labelFormatter.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,21 @@ buster.testCase('Label formatters', {
5252

5353
"returns sentence cased name when label is not found": function(){
5454
assert.equals('Some attribute is required', this.model.preValidate('some_attribute', ''));
55+
},
56+
57+
"returns sentence cased name when label attribute is not defined": function(){
58+
var Model = Backbone.Model.extend({
59+
validation: {
60+
someAttribute: {
61+
required: true
62+
}
63+
}
64+
});
65+
66+
var model = new Model();
67+
_.extend(model, Backbone.Validation.mixin);
68+
69+
assert.equals('Some attribute is required', model.preValidate('someAttribute', ''));
5570
}
5671
},
5772

0 commit comments

Comments
 (0)
0