<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -31,6 +31,24 @@
  *   Validates.Length(&quot;password&quot;, { within: [6, 40] });
  *
  *
+ *** Shared options
+ *
+ * All validations share the following options:
+ *
+ * - +allowBlank+ - Skip validation if attribute is blank (a string that only
+ *   contains whitespace)
+ * - +allowNull+ - Skip validation if attribute is null (or a zero-length
+ *   string)
+ * - &lt;tt&gt;&quot;if&quot;&lt;/tt&gt; - Skip validation if condition fails
+ * - +unless+ - Skip validation if condition passes
+ *
+ * All local validations additionally share the following options:
+ *
+ * - +message+ - A custom error message
+ * - +onFail+ - A callback executed when the validation fails
+ * - +onPass+ - A callback executed when the validation passes
+ *
+ *
  *** Extension
  *
  * NOTE: To customize the appearance of validations, see Validates.Base.Effect.
@@ -56,7 +74,7 @@ var GoodForm = {
    * References all local validations defined on a page, by name.
    *
    *   Validates.Acceptance(&quot;privacy_policy&quot;);
-   *   GoodForm.local.privacy_policy; // [GoodForm.Validation object]
+   *   GoodForm.local.privacy_policy; // =&gt; [GoodForm.Validation object]
    */
   local: {},
 
@@ -100,9 +118,9 @@ var GoodForm = {
    * GoodForm.validMessages nodes can be overridden for any form element
    * name.
    *
-   *   Validate(&quot;login&quot;); // null
+   *   Validate(&quot;login&quot;); // =&gt; null
    *   GoodForm.validMessages[&quot;login&quot;] = &quot;That's a nice name!&quot;
-   *   Validate(&quot;login&quot;); // &quot;That's a nice name!&quot;
+   *   Validate(&quot;login&quot;); // =&gt; &quot;That's a nice name!&quot;
    */
   validMessages: {},
 
@@ -124,12 +142,12 @@ var GoodForm = {
    *
    *   var v = new GoodForm.Validation([&quot;field&quot;]);
    *   v.validate = function () { return &quot;is always invalid&quot; };
-   *   Validate(&quot;field&quot;); // false
-   *   GoodForm.Validate.response[&quot;field&quot;]; // [&quot;is always invalid&quot;];
+   *   Validate(&quot;field&quot;); // =&gt; false
+   *   GoodForm.Validate.response[&quot;field&quot;]; // =&gt; [&quot;is always invalid&quot;];
    */
   Validation: function (arg, options) {
     this.elements = GoodForm.Helpers.getElements(arg)
-    if (!this.elements) return; // throw new Error(&quot;'&quot; + arg + &quot;' could not be validated&quot;);
+    if (!this.elements) throw new Error(&quot;'&quot; + arg + &quot;' cannot be validated&quot;);
     if (this.elements.length == 1) this.element = this.elements[0];
     this.name = this.elements[0].name, this.form = this.elements[0].form;
 
@@ -150,8 +168,8 @@ var GoodForm = {
       switch (true) {
         case (this.allowBlank &amp;&amp; (/^\s*$/).test(value)):
         case (this.allowNull &amp;&amp; value == &quot;&quot;):
-        case (this[&quot;if&quot;] &amp;&amp; !this[&quot;if&quot;]()):
-        case (this.unless &amp;&amp; this.unless()):
+        case (this[&quot;if&quot;] &amp;&amp; !this[&quot;if&quot;](this.name)):
+        case (this.unless &amp;&amp; this.unless(this.name)):
           return false;
         default:
           return true;
@@ -179,11 +197,12 @@ var GoodForm = {
    */
   Validates: {
     Base: function (args, configuration) {
-      args = [].splice.call(args, 0); // convert arguments to array
-      var options = GoodForm.Helpers.extractOptions(args);
+      for (var argsAr = [], i = 0, len = args.length; i &lt; len; ++i) // convert arguments to array
+        argsAr.push(args[i]);
+      var options = GoodForm.Helpers.extractOptions(argsAr);
       for (var name in options) configuration[name] = options[name];
-      for (var i = 0, len = args.length; i &lt; len; ++i) {
-        var validation = new GoodForm.Validation(args[i], configuration);
+      for (var i = 0, len = argsAr.length; i &lt; len; ++i) {
+        var validation = new GoodForm.Validation(argsAr[i], configuration);
         if (validation.initialize) validation.initialize();
         validation.register();
       }
@@ -200,8 +219,6 @@ var GoodForm = {
      *
      * - +message+ - A custom error message (default is: &quot;must be
      *   accepted&quot;)
-     * - +allowNull+ - Skip validation if attribute is null (default is
-     *   true).
      * - +accept+ - Specifies value that is considered accepted. The default
      *   value is a string &quot;1&quot;, which makes it easy to relate to an HTML
      *   checkbox.
@@ -209,9 +226,9 @@ var GoodForm = {
     Acceptance: function () {
       GoodForm.Validates.Base(arguments, {
         accept: 1,
-        message: GoodForm.defaultErrorMessages[&quot;accepted&quot;],
+        message: GoodForm.defaultErrorMessages.accepted,
         validate: function () {
-          if (this.getValue() != this.accept)
+          if (this.getValue()[0] != this.accept)
             return this.message;
         }
       });
@@ -249,12 +266,12 @@ var GoodForm = {
      *   Validates.Confirmation(&quot;password&quot;);
      *   document.getElementById(&quot;password_confirmation&quot;).value = &quot;differ&quot;;
      *   Validate.All();
-     *   Errors[&quot;password&quot;]; // null (returns &quot;doesn't match confirmation&quot; in Active Record)
-     *   Errors[&quot;password_confirmation&quot;]; // [&quot;doesn't match&quot;]
+     *   Errors[&quot;password&quot;]; // =&gt; null (returns &quot;doesn't match confirmation&quot; in Active Record)
+     *   Errors[&quot;password_confirmation&quot;]; // =&gt; [&quot;doesn't match&quot;]
      */
     Confirmation: function () {
       GoodForm.Validates.Base(arguments, {
-        message: GoodForm.defaultErrorMessages[&quot;confirmation&quot;],
+        message: GoodForm.defaultErrorMessages.confirmation,
         initialize: function () {
           var confirmationId = this.element.id + &quot;_confirmation&quot;;
           this.original = this.element;
@@ -288,7 +305,7 @@ var GoodForm = {
      */
     Exclusion: function () {
       GoodForm.Validates.Base(arguments, {
-        message: GoodForm.defaultErrorMessages[&quot;exclusion&quot;],
+        message: GoodForm.defaultErrorMessages.exclusion,
         validate: function () {
           var value = this.getValue();
           for (var i = 0, len = this[&quot;in&quot;].length; i &lt; len; ++i)
@@ -319,7 +336,7 @@ var GoodForm = {
      */
     Format: function () {
       GoodForm.Validates.Base(arguments, {
-        message: GoodForm.defaultErrorMessages[&quot;invalid&quot;],
+        message: GoodForm.defaultErrorMessages.invalid,
         validate: function () {
           if (!this[&quot;with&quot;].test(this.getValue()))
             return this.message;
@@ -339,14 +356,10 @@ var GoodForm = {
      * - +&quot;in&quot;+ - An array of available items
      * - +message+ - Specifies a custom error message (default is: &quot;is not
      *   included in the list&quot;)
-     * - +allowNull+ - If set to true, skips this validation if the
-     *   attribute is null (default is: false)
-     * - +allowBlank+ - If set to true, skips this validation if the
-     *   attribute is blank (default is: false)
      */
     Inclusion: function () {
       GoodForm.Validates.Base(arguments, {
-        message: GoodForm.defaultErrorMessages[&quot;inclusion&quot;],
+        message: GoodForm.defaultErrorMessages.inclusion,
         validate: function () {
           var value = this.getValue();
           for (var i = 0, len = this[&quot;in&quot;].length; i &lt; len; ++i)
@@ -376,8 +389,6 @@ var GoodForm = {
      * - +within+ - An array specifying the minimum and maximum size of the
      *   attribute
      * - +&quot;in&quot;+ - Synonyms (aliases) for +within+
-     * - +allowNull+ - Attribute may be null; skip validation.
-     * - +allowBlank+ - Attribute may be blank; skip validation.
      * - +tooLong+ - The error message if the attribute goes over the
      *   maximum (default is: &quot;is too long (maximum is %d characters)&quot;)
      * - +tooShort+ - The error message if the attribute goes under the
@@ -403,14 +414,14 @@ var GoodForm = {
         validate: function () {
           var len = this.getValue().length;
           if (this.minimum == this.maximum &amp;&amp; len != this.minimum)
-            return (this.wrongLength || this.message
-              || GoodForm.defaultErrorMessages.wrongLength).replace(/%d/g, this.minimum);
+            return (this.wrongLength || this.message ||
+              GoodForm.defaultErrorMessages.wrongLength).replace(/%d/g, this.minimum);
           if (len &lt; this.minimum)
-            return (this.tooShort || this.message
-              || GoodForm.defaultErrorMessages.tooShort).replace(/%d/g, this.minimum);
+            return (this.tooShort || this.message ||
+              GoodForm.defaultErrorMessages.tooShort).replace(/%d/g, this.minimum);
           if (this.maximum &amp;&amp; len &gt; this.maximum)
-            return (this.tooLong || this.message
-              || GoodForm.defaultErrorMessages.tooLong).replace(/%d/g, this.maximum);
+            return (this.tooLong || this.message ||
+              GoodForm.defaultErrorMessages.tooLong).replace(/%d/g, this.maximum);
       }});
     },
 
@@ -428,8 +439,6 @@ var GoodForm = {
      * - +message+ - A custom error message (default is: &quot;is not a number&quot;)
      * - +onlyInteger+ - Specifies whether the value has to be an integer,
      *   e.g. an integral value (default is false)
-     * - +allowNull+ - Skip validation if attribute is null (default is
-     *   false).
      * - +greaterThan+ - Specifies the value must be greater than the
      *   supplied value
      * - +greaterThanOrEqualTo+ - Specifies the value must be greater than
@@ -486,7 +495,7 @@ var GoodForm = {
      */
     Presence: function () {
       GoodForm.Validates.Base(arguments, {
-        message: GoodForm.defaultErrorMessages[&quot;blank&quot;],
+        message: GoodForm.defaultErrorMessages.blank,
         validate: function () {
           if (/^\s*$/.test(this.getValue()))
             return this.message;
@@ -511,8 +520,8 @@ var GoodForm = {
      * or a custom string stating validity:
      *
      *   { email: [&quot;is invalid&quot;] } // Invalid
-     *   { email: null }       // Valid
-     *   { email: &quot;OK&quot; }       // Valid with message
+     *   { email: null }           // Valid
+     *   { email: &quot;OK&quot; }           // Valid with message
      *
      * Configuration options:
      *
@@ -575,11 +584,10 @@ var GoodForm = {
     Name: function (input, options) {
       var name = typeof input == &quot;string&quot; ? input : input.name;
       options = GoodForm.Helpers.extractOptions(options);
-      if (!options.defer) {
+      if (!options.defer)
         GoodForm.Validate.responses = {}, GoodForm.Validate.callbacks = {};
-      }
-      if (options.remote !== false &amp;&amp; !GoodForm.Validate.Queue(name, options))
-        var response = GoodForm.Validate.Queue(name, options); // remote: false
+      if (!(options.remote !== false) || !GoodForm.Validate.Queue(name, { remote: true }))
+        var response = GoodForm.Validate.Queue(name, { remote: false });
       if (!options.defer) return GoodForm.Validate.Run();
       return response;
     },
@@ -594,15 +602,15 @@ var GoodForm = {
       if (!validations) return false;
       for (var i = 0, len = validations.length; i &lt; len; ++i) {
         var validation = validations[i];
-        if (options.form &amp;&amp; validation.form != options.form) return;
+        if (options.scope &amp;&amp; validation.form != options.scope) return;
         var error = validation.validate();
-        if (error) {
+        if (error) { // Handle callbacks
           GoodForm.Validate.responses[name] =
-            (GoodForm.Validate.responses[name] || []).concat(error)
+            (GoodForm.Validate.responses[name] || []).concat(error);
           if (validation.onError) GoodForm.Validate.callbacks[name] =
-            (GoodForm.Validate.callbacks[name] || []).concat(validation.onError)
+            (GoodForm.Validate.callbacks[name] || []).concat(validation.onError);
         } else if (validation.onValid) GoodForm.Validate.callbacks[name] =
-            (GoodForm.Validate.callbacks[name] || []).concat(validation.onValid)
+            (GoodForm.Validate.callbacks[name] || []).concat(validation.onValid);
       }
       if (!GoodForm.Validate.responses[name] &amp;&amp; type == &quot;local&quot;)
         GoodForm.Validate.responses[name] = GoodForm.validMessages[name] ||
@@ -614,13 +622,15 @@ var GoodForm = {
      * Runs every validation on the page (can be scoped with one argument
      * to a specific form).
      */
-    All: function (form) {
+    All: function (form, options) {
+      options = GoodForm.Helpers.extractOptions(options);
       GoodForm.Validate.responses = {}, GoodForm.Validate.callbacks = {};
-      for (var name in GoodForm.remote)
-        GoodForm.Validate.Name(name, { defer: true, scope: form });
+      if (options.remote !== false)
+        for (var name in GoodForm.remote)
+          GoodForm.Validate.Name(name, { remote: true, defer: true, scope: form });
       for (var name in GoodForm.local)
-        // if (!GoodForm.Validate.responses[name])
-        GoodForm.Validate.Name(name, { defer: true, scope: form });
+        // if (!GoodForm.Validate.ajaxQuery[name])
+          GoodForm.Validate.Name(name, { remote: false, defer: true, scope: form });
 
       return GoodForm.Validate.Run();
     },
@@ -644,7 +654,6 @@ var GoodForm = {
         for (var i = 0; value = values[i]; ++i)
           params.push(name + &quot;=&quot; + encodeURIComponent(value));
       }
-
       if (params.length &lt; 1) return false;
       var t, loadingState;
       try { t = new XMLHttpRequest(); } catch(e) {
@@ -655,14 +664,20 @@ var GoodForm = {
         if (t.readyState == 4 &amp;&amp; t.status &gt;= 200 &amp;&amp; t.status &lt; 300) {
           eval(&quot;var json = &quot; + t.responseText);
           for (var name in json)
-            new GoodForm.Validate.Effect(name, json[name]);
+            if (name == &quot;__eval__&quot;)
+              eval(json[name]);
+            else
+              new GoodForm.Validate.Effect(name, json[name]);
+          for (var name in GoodForm.Validate.responses)
+            if (!json[name])
+              new GoodForm.Validate.Effect(name, GoodForm.Validate.responses[name]);
         } else if (!loadingState)
           for (var name in GoodForm.Validate.ajaxQuery)
-            new GoodForm.Validate.Effect(name); // No response: loading.
+            new GoodForm.Validate.Effect(name); // No response: loading
       }
 
       var baseUri = location.protocol + &quot;//&quot; + location.host + GoodForm.remotePath;
-      t.open(&quot;GET&quot;, baseUri + &quot;?&quot; + params.join(&quot;&amp;&quot;));
+      t.open(&quot;GET&quot;, baseUri + &quot;?&quot; + params.join(&quot;&amp;&quot;), true);
       t.setRequestHeader(&quot;Content-Type&quot;, &quot;application/x-www-form-urlencoded&quot;);
       t.send(null);
       return true;
@@ -757,6 +772,7 @@ var GoodForm = {
     },
 
     extractName: function (input) {
+      var el;
       if (input.name)
         return input.name;
       else if (el = document.getElementById(input))
@@ -766,12 +782,11 @@ var GoodForm = {
     },
 
     /*
-     * Returns a validation span for GoodForm.Validate.Effect, creating a
-     * new one if it does not exist.
+     * Returns a validation span for GoodForm.Validate.Effect, creating a new
+     * one if it does not exist.
      */
     findOrCreateValidationSpan: function(name) {
-      var id = GoodForm.Helpers.underscore(name) + &quot;_validation&quot;;
-
+      var vEl, fEl, id = GoodForm.Helpers.underscore(name) + &quot;_validation&quot;;
       if (vEl = document.getElementById(id)) return vEl;
       vEl = document.createElement(&quot;span&quot;);
       vEl.id = id;
@@ -790,13 +805,13 @@ var GoodForm = {
     getValuesByName: function (name, form) {
         var els = document.getElementsByName(name), values = [];
         if (form &amp;&amp; form.constructor == String)
-            form = document.getElementById(form);
+          form = document.getElementById(form);
         for (var i = 0, len = els.length; el = els[i]; ++i)
-            if (!form || form == el.form)
-                if (el.checked || !/checkbox|radio/.test(el.type))
-                    values.push(el.value);
-                else if (len == 1)
-                    values.push(&quot;&quot;); // For the unchecked
+          if (!form || form == el.form)
+            if (el.checked || !/checkbox|radio/.test(el.type))
+              values.push(el.value);
+            else if (len == 1)
+              values.push(&quot;&quot;); // For the unchecked
         return values.length &gt; 1 ? values : values[0];
     },
 
@@ -819,7 +834,7 @@ var GoodForm = {
      * underscore. The string will retain alphanumerical start and end
      * points.
      *
-     *   GoodForm.Helpers.underscore(&quot;user[email]&quot;); // &quot;user_email&quot;
+     *   GoodForm.Helpers.underscore(&quot;user[email]&quot;); // =&gt; &quot;user_email&quot;
      */
     underscore: function (string) {
       return string.toLowerCase().replace(/[^\w]+/g, &quot;_&quot;).</diff>
      <filename>good_form.js</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>537879bb05cd5275cdd8435ce3c6ccf9cc6f12cb</id>
    </parent>
  </parents>
  <author>
    <name>tom g</name>
    <email>tomekg@avtag.com</email>
  </author>
  <url>http://github.com/stephencelis/good_form/commit/af55bb28349f280eb09d7f2d4c39ae9f931bbdc5</url>
  <id>af55bb28349f280eb09d7f2d4c39ae9f931bbdc5</id>
  <committed-date>2009-01-26T08:28:09-08:00</committed-date>
  <authored-date>2009-01-26T07:39:14-08:00</authored-date>
  <message>Add IE6 compatibility

Signed-off-by: Stephen Celis &lt;stephen.celis@gmail.com&gt;</message>
  <tree>43d25d7f0b97d30683d40724b35a1714de0aaa53</tree>
  <committer>
    <name>Stephen Celis</name>
    <email>stephen.celis@gmail.com</email>
  </committer>
</commit>
