Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>model.save() performs a validation first (validate method on the model). If it successfull, it then does the POST/PUT to the server. In other words, you get a false if the client side validation fails. It won't post to server then. You can't use the deferred object if this fails because false.always() will probally result in an error.</p> <p>Alsoo, if you don't pass a wait: true in the model.save options, it will update the model with its validated object. I usually pass wait: true just to be sure. (I don't want to render the element twice).</p> <p>If the model fails the client side validation, then it should also fail the server side validation. In this case there is an "invalid" event to listen to. So you only should be interested in the success call. Which in theory should only be interesting if it really has updates (would fire a "change" event)</p> <pre><code>add: { var self = this; this.model.on('invalid', function(error){ console.log(error, 'model is invalid. Check model.validate') }); this.model.on('change', function(model){ console.log(model.toJSON(), 'model has successfully changed') }); this.model.on('error', function(error){ console.log("server failed to acknowledge (server connection not made)") }); this.model.on('sync', function(resp){ console.log("server successfull acknowledged (server connection made)") }); this.model.save( { title:$("#addNew input:eq(0)").val(), completed:$("#addNew input:eq(1)").val() }, { wait: true, success: function (model, response) { console.log("success"); #fires an change event if the model is updated self.complete(); }, error: function (model, response) { console.log("error"); self.complete(); } } ); }, complete: function(){ console.log("show this") } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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