From: uw
Date: Mon May 21 21:29:13 2001
Added files:
      php-lib/pages/form/xml/tests/form_date.php
      php-lib/pages/form/xml/tests/form_date.xml

Modified files:
      php-lib/php/form/elements/form_element_date.inc

Log message:
- added date example
- now button JavaScript is broken :/


Index: php-lib/php/form/elements/form_element_date.inc
diff -u php-lib/php/form/elements/form_element_date.inc:1.6 
php-lib/php/form/elements/form_element_date.inc:1.7
--- php-lib/php/form/elements/form_element_date.inc:1.6 Sun May 20 19:20:51 2001
+++ php-lib/php/form/elements/form_element_date.inc     Mon May 21 21:28:41 2001
@@ -6,7 +6,7 @@
 *
 * Use this meta element to make sure that the user enters a valid date.
 *
-* @version  $Id: form_element_date.inc,v 1.6 2001/05/20 17:20:51 uw Exp $
+* @version  $Id: form_element_date.inc,v 1.7 2001/05/21 19:28:41 uw Exp $
 */
 class form_element_date extends form_element_dateobject {
 
@@ -22,7 +22,7 @@
                                                                                       
                                                 
                                                                                       
                                                 "language"                            
  => "string",
                                                                                       
                                                 
-                                                                                      
                                                 "intro"                               
          => "string",
+                                                                                      
+                                                 "intro"                              
+           => "array",
                                                                                       
                                                 "intro_e"                             
          => "string",
                                                                                       
                                                 
                                                                                       
                                                 "min_year_long"         => "integer",
@@ -80,7 +80,7 @@
        /**
        * Intro option.
        * 
-       * @var  string
+       * @var  array
        */
        var $intro = "";
        
@@ -118,7 +118,7 @@
                        
                if ($this->max_year_short < 0)
                        $this->max_year_short = date("y");
-               
+      
        } // end func setup
        
        /**
@@ -302,10 +302,13 @@
        
        function generateButton() {
                
-               return sprintf('<input type="submit" name="%s_button" value="%s" 
onClick="form_date_now(\'%s\'); return false;">', 
+    list($format, $values) = $this->getExtraJSValues();
+               return sprintf('<input type="submit" name="%s_button" value="%s" 
+onClick="form_date_now(\'%s\', \'%s\', [%s]); return false;">', 
                                                                                
$this->name,
                                                                                
$this->now,
-                                                                               
$this->name
+                                                                               
+$this->name,
+                    $format,
+                    $values
                                                                        );
                                                                                
        } // end func generateButton
@@ -327,8 +330,10 @@
                                                                                       
 $this->CR_HTML
                                                                        );
                
-               if ($this->intro_e)
-                       $html .= sprintf('<option value="%s">%s</option>%s', 
$this->intro, $this->intro, $this->CR_HTML);
+               if ($this->intro_e) {
+      foreach ($this->intro as $intro_value => $intro_label) 
+                       $html .= sprintf('<option value="%s">%s</option>%s', 
+$intro_value, $intro_label, $this->CR_HTML);
+    }
                                                                
                foreach ($options as $k => $option)
                        $html .= sprintf('<option value="%s"%s>%s</option>%s', 
@@ -372,22 +377,11 @@
                return $value;
        }
        
-       /**
-       * @param        string  Elementname Suffix
-
        function getJSonActivation($name) {
-               
-               if ("strong" == $this->js_mode && $this->form_name)
-                       return sprintf(' onChange="_%s.validate(\'%s_%s\')" ',
-                                                                                      
 $this->form_name,
-                                                                                      
 $this->name,
-                                                                                      
 $name
-                                                                               );
-
+    return "";         
        } // end func getJSonActivation
-       */
                
-function getJSvalue() {
+  function getJSvalue() {
        
                $js = 'function form_date(f, e) {
        var v = s = n = "";
@@ -412,38 +406,49 @@
        
        function getExtraJS() {
 
-               $values = "";
-               $format = "";
-               $len = strlen($this->format);
-               for ($i = 0; $i < $len; $i++)
-                       if (preg_match("/[aAdDFhHgGijlmnMswYyz]/", $this->format{$i})) 
{
-                               $format .= $this->format{$i};
-                               $values .= sprintf('"%s", ', 
$this->getPreloadValue($this->format{$i}));
-                       }
-               $values = substr($values, 0, -2);
+               list($format, $values) = $this->getExtraJSValues();
 
-               $js = sprintf('function form_date_now(e) {
-       var i = j = f = v = 0;
-       
-       v = [%s];
-       f = "%s";
+               $js = sprintf('function form_date_now(e, f, v) {
+       var i = j = 0;
 
        for (i = 0; i < f.length; i++)
-               with (document.forms["%s"].elements[e + f.substring(i, i + 1)])
+               with (document.forms["%s"].elements[e + "_" + f.substring(i, i + 1)])
                        for (j = 0; j < options.length; j++)
-                               if (options[j].value.toString() == v[i]) {
+                               if (options[j].value.toString() == v[i].toString) {
                                        options[j].selected = true;
                                        break;
-                               }
+        }
 
 }',
-                                                       $values,
-                                                       $format,
                                                        $this->form_name
                                                );
 
                return array($js, "form_date_now", "JavaScript1.2");
        } // end func getExtraJS
-       
+
+  
+  /**
+  * Returns format and value required for the extra JS function.
+  * 
+  * @return array [format, values]
+  * @see  getExtraJS()
+  */
+  function getExtraJSValues() {
+    #static $values = "", $format = "";
+    
+    if ($format)
+      return array($format, $values);
+
+               $len = strlen($this->format);
+               for ($i = 0; $i < $len; $i++)
+                       if (preg_match("/[aAdDFhHgGijlmnMswYyz]/", $this->format{$i})) 
+{
+                               $format .= $this->format{$i};
+                               $values .= sprintf('%s, ', 
+$this->getPreloadValue($this->format{$i}));
+                       }
+               $values = substr($values, 0, -2);
+    
+    return array($format, $values);
+  } // end func getExtraJSValues
+  
 } // end class form_elements_date
 ?>



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to