Revision: 2477
          https://sourceforge.net/p/mrbs/code/2477/
Author:   cimorrison
Date:     2012-10-09 13:07:42 +0000 (Tue, 09 Oct 2012)
Log Message:
-----------
Fixed bug causing a JavaScript error when not logged in

Modified Paths:
--------------
    mrbs/branches/improved_repeat_interface/web/js/edit_entry.js.php

Modified: mrbs/branches/improved_repeat_interface/web/js/edit_entry.js.php
===================================================================
--- mrbs/branches/improved_repeat_interface/web/js/edit_entry.js.php    
2012-10-05 17:20:16 UTC (rev 2476)
+++ mrbs/branches/improved_repeat_interface/web/js/edit_entry.js.php    
2012-10-09 13:07:42 UTC (rev 2477)
@@ -141,6 +141,7 @@
 ?>
 function validationMessages()
 {
+  var field, label;
   <?php
   // First of all create a property in the vocab object for each of the 
mandatory
   // fields.    These will be the 'name' and 'rooms' fields and any other 
fields
@@ -166,44 +167,48 @@
   ?>
   for (var key in validationMessages.vocab)
   {
-    validationMessages.vocab[key] = $("label[for=" + key + "]").html();
-    validationMessages.vocab[key] = '"' + 
validationMessages.vocab[key].replace(/:$/, '') + '" ';
-    validationMessages.vocab[key] += '<?php echo 
escape_js(get_vocab("is_mandatory_field")) ?>';
+    label = $("label[for=" + key + "]");
+    if (label.length > 0)
+    {
+      validationMessages.vocab[key] = label.html();
+      validationMessages.vocab[key] = '"' + 
validationMessages.vocab[key].replace(/:$/, '') + '" ';
+      validationMessages.vocab[key] += '<?php echo 
escape_js(get_vocab("is_mandatory_field")) ?>';
     
-    var field = document.getElementById(key);
-    if (field.setCustomValidity && field.willValidate)
-    {
-      <?php
-      // We define our own custom event called 'validate' that is triggered on 
the
-      // 'change' event for checkboxes and select elements, and the 'input' 
even
-      // for all others.   We cannot use the change event for text input 
because the
-      // change event is only triggered when the element loses focus and we 
want the
-      // validation to happen whenever a character is input.   And we cannot 
use the
-      // 'input' event for checkboxes or select elements because it is not 
triggered
-      // on them.
-      ?>
-      $(field).bind('validate', function(e) {
+      field = document.getElementById(key);
+      if (field.setCustomValidity && field.willValidate)
+      {
         <?php
-        // need to clear the custom error message otherwise the browser will
-        // assume the field is invalid
+        // We define our own custom event called 'validate' that is triggered 
on the
+        // 'change' event for checkboxes and select elements, and the 'input' 
even
+        // for all others.   We cannot use the change event for text input 
because the
+        // change event is only triggered when the element loses focus and we 
want the
+        // validation to happen whenever a character is input.   And we cannot 
use the
+        // 'input' event for checkboxes or select elements because it is not 
triggered
+        // on them.
         ?>
-        e.target.setCustomValidity("");
-        if (!e.target.validity.valid)
-        {
-          
e.target.setCustomValidity(validationMessages.vocab[$(e.target).attr('id')]);
-        }
-      });
-      $(field).filter('select, [type="checkbox"]').bind('change', function(e) {
-        $(this).trigger('validate');
-      });
-      $(field).not('select, [type="checkbox"]').bind('input', function(e) {
-        $(this).trigger('validate');
-      });
-      <?php
-      // Trigger the validate event when the form is first loaded
-      ?>
-      $(field).trigger('validate');
-    }
+        $(field).bind('validate', function(e) {
+          <?php
+          // need to clear the custom error message otherwise the browser will
+          // assume the field is invalid
+          ?>
+          e.target.setCustomValidity("");
+          if (!e.target.validity.valid)
+          {
+            
e.target.setCustomValidity(validationMessages.vocab[$(e.target).attr('id')]);
+          }
+        });
+        $(field).filter('select, [type="checkbox"]').bind('change', 
function(e) {
+          $(this).trigger('validate');
+        });
+        $(field).not('select, [type="checkbox"]').bind('input', function(e) {
+          $(this).trigger('validate');
+        });
+        <?php
+        // Trigger the validate event when the form is first loaded
+        ?>
+        $(field).trigger('validate');
+      }
+    } <?php // if (label.length > 0) ?>
   }
 }
 
------------------------------------------------------------------------------
Don't let slow site performance ruin your business. Deploy New Relic APM
Deploy New Relic app performance management and know exactly
what is happening inside your Ruby, Python, PHP, Java, and .NET app
Try New Relic at no cost today and get our sweet Data Nerd shirt too!
http://p.sf.net/sfu/newrelic-dev2dev
_______________________________________________
Mrbs-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mrbs-commits

Reply via email to