Note that there are some explanatory texts on larger screens.

plurals
  1. POValidate on save and save().complete - in backbone
    text
    copied!<p>I have problem with validation in my model. It seems that it is impossible to use save().complete(function() {..... in the same time as validation- here is the code:</p> <p>my model:</p> <pre><code> App.Models.Task = Backbone.Model.extend({ defaults: { title:'', completed: 0 }, validate: function (attrs, options) { if(attrs.title == '' || attrs.title === undefined) { return "fill title pls" } }, urlRoot: 'tasks' }); </code></pre> <p>and then in my view i try to save it in add method :</p> <pre><code> App.Views.TaskAdd = Backbone.View.extend({ tagName: 'div', template: template('taskTemplateAdd'), events : { 'click .addTask' : 'add' }, initialize: function () { this.model.on('add',this.render, this) }, add : function () { var title = $("#addNew input:eq(0)").val(); var completed = $("#addNew input:eq(1)").val(); this.model.set('title', title); this.model.set('completed', completed); this.model.save({}, { success: function (model, response) { console.log("success"); }, error: function (model, response) { console.log("error"); } }).complete(function () { $("&lt;div&gt;Data sent&lt;/div&gt;").dialog(); $('#list').empty(); }); }, render: function () { this.$el.html(this.template(this.model.toJSON())); return this } }); </code></pre> <p>when validate fires i get error : </p> <pre><code>Uncaught TypeError: Object false has no method 'complete' </code></pre> <p>I understand that it tries probably to run complete callback on the return value but how to solve this problem ???</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload