When I call isValid()
on my backbone model it always returns undefined
even when the validation rules have been met or not. What could be going wrong here?
What could be the problem here and how can I fix it?
My Model:
Backbone.Model.extend({
validation: {
firstname: { required: true, msg: _('First Name is required').translate() }
, lastname: { required: true, msg: _('Last Name is required').translate() }
}
});
My view:
Backbone.View.extend({
events: {
'submit form[data-action="specify-pbt"]': 'specifyPBT'
}
, bindings: {
'[name="firstname"]': 'firstname'
, '[name="lastname"]': 'lastname'
}
, initialize: function(options) {
this.model = options.model || new PBTSpecifyModel(); // The latter condition is always met
BackboneCompositeView.add(this);
BackboneFormView.add(this);
Backbone.Validation.bind(this);
}
, specifyPBT: function (e)
{
var options = jQuery(e.target).serializeObject();
console.log("model: ");
console.log(this.model); // Outputs the model: looks all correct
console.log("isValid: ");
console.log(this.model.isValid()); // Outputs undefined
console.log("validationError: ");
console.log(this.model.validationError); // Outputs null
}
, getContext: function()
{
return {
}
}
})
});