[Pkg-javascript-commits] [backbone] 33/34: documenting the 'error' callback and it's overriding behavior.

Jonas Smedegaard js at moszumanska.debian.org
Sat May 3 16:58:46 UTC 2014


This is an automated email from the git hooks/post-receive script.

js pushed a commit to tag 0.1.2
in repository backbone.

commit 3e3c292c48f2159e545750a392c3da1c35743797
Author: Jeremy Ashkenas <jashkenas at gmail.com>
Date:   Tue Oct 19 11:26:16 2010 -0400

    documenting the 'error' callback and it's overriding behavior.
---
 index.html | 33 ++++++++++++++++++++++++++-------
 1 file changed, 26 insertions(+), 7 deletions(-)

diff --git a/index.html b/index.html
index b2e4929..85cdef0 100644
--- a/index.html
+++ b/index.html
@@ -500,17 +500,20 @@ new Book({
       change the models state, a <tt>"change"</tt> event will be fired, unless
       <tt>{silent: true}</tt> is passed as an option.
     </p>
+    
+<pre>
+note.set({title: "October 12", content: "Lorem Ipsum Dolor Sit Amet..."});
+</pre>
 
     <p>
       If the model has a <a href="#Model-validate">validate</a> method,
-      it will be validated before the attributes are set, and no changes will
-      occur if the validation fails.
+      it will be validated before the attributes are set, no changes will
+      occur if the validation fails, and <b>set</b> will return <tt>false</tt>. 
+      You may also pass an <tt>error</tt> 
+      callback in the options, which will be invoked instead of triggering an 
+      <tt>"error"</tt> event, should validation fail.
     </p>
 
-<pre>
-note.set({title: "October 12", content: "Lorem Ipsum Dolor Sit Amet..."});
-</pre>
-
     <p id="Model-unset">
       <b class="header">unset</b><code>model.unset(attribute, [options])</code>
       <br />
@@ -605,7 +608,8 @@ setInterval(function() {
       (HTTP <tt>POST</tt>), if the model already
       exists on the server, the save will be an <tt>"update"</tt> (HTTP <tt>PUT</tt>). Accepts
       <tt>success</tt> and <tt>error</tt> callbacks in the options hash, which
-      are passed <tt>(model, response)</tt> as arguments.
+      are passed <tt>(model, response)</tt> as arguments. The <tt>error</tt> callback will
+      also be invoked if the model has a <tt>validate</tt> method, and validation fails.
     </p>
 
     <p>
@@ -678,6 +682,21 @@ one.set({
 });
 </pre>
 
+    <p>
+      <tt>"error"</tt> events are useful for providing coarse-grained error 
+      messages at the model or collection level, but if you have a specific view
+      that can better handle the error, you may override and suppress the event 
+      by passing an <tt>error</tt> callback directly:
+    </p>
+    
+<pre>
+account.set({access: "unlimited"}, {
+  error: function(model, error) {
+    alert(error);
+  }
+});
+</pre>
+
     <p id="Model-url">
       <b class="header">url</b><code>model.url()</code>
       <br />

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/backbone.git



More information about the Pkg-javascript-commits mailing list