Commits

Sascha Köhler committed 82a4cbf

ENHANCEMENT CustomHtmlForm javascripts play nice with other namespaces than jQuery. BUGFIX DateField get's initialised correctly now and can show calendar popups.

Comments (0)

Files changed (5)

code/CustomHtmlForm.php

             
             $this->controller->addJavascriptSnippet($javascriptSnippets['javascriptSnippets']);
             $this->controller->addJavascriptOnloadSnippet($javascriptSnippets['javascriptOnloadSnippets']);
+            $this->controller->addJavascriptOnloadSnippet($this->getJavascriptFieldInitialisations());
         }
 
         // Register the default module directory from mysite/_config.php
     }
 
     /**
+     * Returns javascript code for fields that need special initialisation,
+     * e.g. the datepicker field
+     *
+     * @return string
+     *
+     * @author Sascha Koehler <skoehler@pixeltricks.de>
+     * @since 28.02.2012
+     */
+    public function getJavascriptFieldInitialisations() {
+        $snippet    = '';
+        $formFields = $this->getFormFields();
+
+        foreach ($this->fieldGroups as $groupName => $groupFields) {
+            foreach ($groupFields as $fieldName => $fieldDefinition) {
+                if ($fieldDefinition['type'] == 'DateField') {
+                    $snippet .= "$('input[name=\"".$fieldName."\"]').datepicker();"."\n";
+                }
+            }
+        }
+
+        return $snippet;
+    }
+
+    /**
      * Returns JS commands for JS validators init
      *
      * @return array

code/CustomHtmlFormPage.php

 
                 '.$snippetStr.'
 
-                $(document).ready(function() {
+                (function($) {jQuery(document).ready(function() {
                     '.$onLoadSnippetStr.'
                     '.$onLoadInTheEndSnippetStr.'
-                });
+                })})(jQuery);
             ');
         }
     }

script/jquery.pixeltricks.forms.checkFormData.js

 /**
  * Methoden zur Feldpruefung.
  */
-pixeltricks.forms.checkFormData = function()
+(function($) { pixeltricks.forms.checkFormData = function()
 {
     /**
      * Workaround fuer Selbstreferenzierung in Closures.
     {
         this.fieldType = fieldType;
     }
-}
+}})(jQuery);

script/jquery.pixeltricks.forms.events.js

  * @since 11.11.2010
  * @license none
  */
-pixeltricks.forms.events = function()
+(function($) { pixeltricks.forms.events = function()
 {
     /**
      * Workaround fuer Selbstreferenzierung in Closures.
     {
         that.fieldName = fieldName;
     }
-}
+}})(jQuery);

script/jquery.pixeltricks.forms.validator.js

 /**
  * Formular Validator.
  */
-pixeltricks.forms.validator = function()
-{
+(function($) {pixeltricks.forms.validator = function() {
     /**
      * Enthaelt die Definitionen der zu pruefenden Formularfelder.
      */
         }
     }
 }
+})(jQuery);