backbone.js - Backbone.validation not working on save -
i have simple model using backbone.validations plugin.
var locationmodel = backbone.model.extend({ validation: { location_name: { required : true, msg : 'a name required location' } } // end validation }); var test = new locationmodel(); test.url = 'http://link-goes-here'; test.save(); it appears on save event, it's going ahead , saving empty model though attribute "location_name" required?
i did bunch of testing , way consistently not send request creating defaults on model:
var locationmodel = backbone.model.extend({ defaults: { location_name: null }, validation: { location_name: { required: true, msg: 'a name required location' } } // end validation }); var test = new locationmodel(); test.on('validated', function() { console.log(arguments); }); test.url = '/echo/json'; test.save(); here's fiddle. if comment out defaults, sends request initially, though validated event saying it's invalid. , fires validated again without sending request.
Comments
Post a Comment