0

I got a validation based on backbone fundamentals by addyosmani, but when i try it on my view i can't get the error that the model generated.TIA

model.js

 validate: function(attrs) {            

        var errors = this.errors = {};
        if (!attrs.box) 
            errors.box= 'box value is required'; 
            //console.log(errors.box); 

        if (!_.isEmpty(errors)) return errors;

 }

view.js

validate: function(model) {
    console.log("error text--" + model.errors[this.input] || '');


 },
koko
  • 31
  • 2
  • 6

1 Answers1

0

Should it be var errors = this errors || {} ;?

Joe
  • 1,841
  • 4
  • 27
  • 43
  • actually this is the code that i'm trying to do. https://github.com/addyosmani/backbone-fundamentals/blob/gh-pages/index.md#better-model-property-validation . but when i use it as a modular it doesn't work anymore – koko Oct 15 '12 at 08:00
  • have you tried to `console.log` the `model` in view.js to see what comes out? My equivalent code in the view is: `$.each(this.model.errors, function(index, value) { // do something with index and value });` – Joe Oct 15 '12 at 09:38