[Jifty-commit] r1910 - jifty/trunk/share/web/static/js

jifty-commit at lists.jifty.org jifty-commit at lists.jifty.org
Thu Aug 31 17:41:23 EDT 2006


Author: nelhage
Date: Thu Aug 31 17:41:22 2006
New Revision: 1910

Modified:
   jifty/trunk/share/web/static/js/calendar.js
   jifty/trunk/share/web/static/js/jifty.js

Log:
Fixing the calendar widget to create a new calendar every time, so
that the calendar reflects any changes the user makes in the text
field.

Modified: jifty/trunk/share/web/static/js/calendar.js
==============================================================================
--- jifty/trunk/share/web/static/js/calendar.js	(original)
+++ jifty/trunk/share/web/static/js/calendar.js	Thu Aug 31 17:41:22 2006
@@ -14,7 +14,8 @@
     },
 
     dateFormat: "Y-m-d",
-
+    dateRegex: /^(\d{4})\W(\d{2})\W(\d{2})/,
+    
     Options: {
         NAV_ARROW_LEFT: "/static/images/yui/us/tr/callt.gif",
         NAV_ARROW_RIGHT: "/static/images/yui/us/tr/calrt.gif"
@@ -30,21 +31,13 @@
             Jifty.Calendar.hideOpenCalendar();
             return;
         }
-
+        
         Jifty.Calendar.hideOpenCalendar();
         
         /* We need to delay Jifty's canonicalization until after we've
            selected a value via the calendar */
-        input["_onblur"] = input.onblur;
-        input.onblur     = null;
+        Form.Element.disableValidation(input);
         
-        if ( wrap ) {
-            wrap.style.display = "block";
-            Jifty.Calendar.openCalendar = wrapId;
-            Jifty.Utils.scrollToShow( wrapId );
-            return;
-        }
-
         wrap = document.createElement("div");
         wrap.setAttribute( "id", wrapId );
         
@@ -57,8 +50,8 @@
 
         var cal;
         
-        if ( /^(\d{4})\W(\d{2})\W(\d{2})/.test(input.value) ) {
-            var bits = input.value.match(/^(\d{4})\W(\d{2})\W(\d{2})/);
+        if (Jifty.Calendar.dateRegex.test(input.value) ) {
+            var bits = input.value.match(Jifty.Calendar.dateRegex);
             cal = new YAHOO.widget.Calendar( calId,
                                              wrapId,
                                              bits[2]+"/"+bits[1],
@@ -89,7 +82,7 @@
         
         cal.setupConfig();
         cal.render();
-        
+
         Jifty.Calendar.openCalendar = wrapId;
         Jifty.Utils.scrollToShow( wrapId );
         /*Jifty.Calendar.preventStutter = wrapId;*/
@@ -99,19 +92,19 @@
 
     hideOpenCalendar: function() {
         if ( Jifty.Calendar.openCalendar && $( Jifty.Calendar.openCalendar ) ) {
-            $( Jifty.Calendar.openCalendar ).style.display = "none";
 
             /* Get the input's ID */
             var inputId = Jifty.Calendar.openCalendar;
                 inputId = inputId.replace(/^cal_/, '');
                 inputId = inputId.replace(/_wrap$/, '');
 
+            Element.remove(Jifty.Calendar.openCalendar);
+
             var input = $( inputId );
 
-            /* Restore the original onblur */
-            input.onblur     = input["_onblur"];
-            input["_onblur"] = null;
-            
+            /* Reenable canonicalization */
+            Form.Element.enableValidation(input);
+
             Jifty.Calendar.openCalendar = "";
         }
     },

Modified: jifty/trunk/share/web/static/js/jifty.js
==============================================================================
--- jifty/trunk/share/web/static/js/jifty.js	(original)
+++ jifty/trunk/share/web/static/js/jifty.js	Thu Aug 31 17:41:22 2006
@@ -309,9 +309,22 @@
 
     // Validates the action this form element is part of
     validate: function (element) {
-        Form.Element.getAction(element).validate();
+            if(!Element.hasClassName(element, 'validation_disabled')) {
+                Form.Element.getAction(element).validate();
+            }
     },
 
+    // Temporarily disable validation
+            disableValidation: function(element) {
+            Element.addClassName(element, 'validation_disabled');
+        },
+
+            //Reenable validation            
+            enableValidation: function(element) {
+            Element.removeClassName(element, 'validation_disabled');
+        },
+
+
     // Look up the form that this element is part of -- this is sometimes
     // more complicated than you'd think because the form may not exist
     // anymore, or the element may have been inserted into a new form.


More information about the Jifty-commit mailing list