简体   繁体   中英

Backbone model validation issue

I plan to use http://thedersen.com/projects/backbone-validation/#examples for model/form validation. But model proceed to save while form is not valid. What is wrong?

_.extend(Backbone.Model.prototype, Backbone.Validation.mixin);

M=Backbone.Model.extend({
    validation:{
        name:{
            required:true
        }
    },
    url:'foo'
})

m=new M();
m.validate();      //return correct validation error.
m.validationError; // this is null while it should be filled by above error
m.save();          // it communicate with server while the model is not valid

Property name has not been set. Try the following code.

M = Backbone.Model.extend({
    defaults: {
        name: null
    },
    validation:{
        name:{
            required:true
        }
    },
    url:'foo'
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM