Note that there are some explanatory texts on larger screens.

plurals
  1. POBackbone Validate is sending a request when validation fails
    primarykey
    data
    text
    <p>According to the backbone documentation about validation it states:</p> <blockquote> <p>If validate returns an error, set and save will not continue, and the model attributes will not be modified.</p> </blockquote> <p>So the way I read that set or save should never run if the validation fails. But that is not the results I am getting. Even when validation fails it still sends the POST/PUT request. Am I reading the docs wrong or doing something incorrect in my code?</p> <p>Here is my relevant code: <a href="https://gist.github.com/80f6ef0099fbe96025dc" rel="nofollow">https://gist.github.com/80f6ef0099fbe96025dc</a></p> <pre><code>App.Models.Test = Backbone.Model.extend( urlRoot: '/api/test' validate: (attrs) -&gt; errors = [] if attrs.to is '' errors.push name: "to" field: "js-to" message: "You must enter a to address" if attrs.subject is '' errors.push name: "subject" field: "js-subject" message: "You must enter a subject" # Return our errors array if it isn't empty errors if errors.length &gt; 0 ) App.Views.Details = Backbone.View.extend( initialize: -&gt; @model.bind "error", @error, this events: "click #js-save": "saveItem" saveItem: (e) -&gt; e.preventDefault() # Set the model then save it. @model.set subject: $("#js-subject").val() message: $("#js-message").val() mailbox_id: $("#js-from").val() to: $("#js-to").val() cc: $("#js-cc").val() bcc: $("#js-bcc").val() tags: App.Helpers.tagsToObject $('#js-tags').val() scope: $('#js-scope').val() attachments: attachments @model.save null, success: (model, response) =&gt; App.Helpers.showAlert "Success!", "Saved Successfully", "alert-success" @next() error: (model, response) -&gt; App.Helpers.showAlert "Error", "An error occurred while trying to save this item", "alert-error" # Show the errors based on validation failure. error: (model, error) -&gt; App.Helpers.displayValidationErrors error </code></pre>
    singulars
    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.
 

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