nealstewart / backbone.validations

Declarative, HTML5 Attribute-Inspired Validations for Backbone
301 stars 37 forks source link

Uncaught TypeError: Cannot read property 'hasOverridenError' of undefined #7

Closed dtuite closed 12 years ago

dtuite commented 12 years ago

Hi. Firstly, awesome plugin. I've been using it a lot today.

I'm trying to explicitly validate a model by calling validate() on it. However, I'm encountering an error:

Uncaught TypeError: Cannot read property 'hasOverridenError' of undefined
          newValidate                                                                 backbone.validations.js:111
          Busables.Views.NewBus.NewBus.saveBus                                      new_bus.js:35
          jQuery.event.dispatch                                                                      jquery.js:3320
          jQuery.event.add.elemData.handle.eventHandle                                jquery.js:2926

I need to call validate explicitly because I want to validate a child model before it's parent is saved.

Any suggestions?

dtuite commented 12 years ago

Right, I'm no JS ninja but here's what I think I've worked out.

Basically, no params are passed into newValidate when it is called on line 266. So then everything blows up when we call params.whatever inside the newValidate function.

I'm not sure what params was meant to be though?

nealstewart commented 12 years ago

Params is the result of some devious things I'm doing to allow this to seamlessly integrate with Backbone's existing validation logic. Can you post the exact code that generated this error to a gist?

dtuite commented 12 years ago

It turns out it was actually my own fault. I thought that I could do something like this.get('route').validatie() but I see now that I need to pass something into validate() like this:

route = this.get('route');
route.validate( route );

You can see what I was doing in this Gist.