Fixed bug #5956: TCA eval required on date field does not work
authorOliver Hader <oliver.hader@typo3.org>
Fri, 23 Nov 2007 14:57:51 +0000 (14:57 +0000)
committerOliver Hader <oliver.hader@typo3.org>
Fri, 23 Nov 2007 14:57:51 +0000 (14:57 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/branches/TYPO3_4-1@2754 709f56b5-9817-0410-a4d7-c38de5d9e867

ChangeLog
t3lib/class.t3lib_tceforms.php
t3lib/jsfunc.evalfield.js
typo3/jsfunc.tbe_editor.js

index aae6cb1..caf6238 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2007-11-23  Oliver Hader  <oh@inpublica.de>
+
+       * Fixed bug #5956: TCA eval required on date field does not work
+
 2007-11-09  Benjamin Mack  <mack@xnos.org>
 
         * (bugfix) Fixed Image Generation bug. Call in t3lib_div now uses the IM wrapper to render gifs/pngs
index 319aaac..04aad12 100755 (executable)
@@ -282,6 +282,7 @@ class t3lib_TCEforms        {
        var $palettesRendered=array();                          // During rendering of forms this will keep track of which palettes has already been rendered (so they are not rendered twice by mistake)
        var $hiddenFieldListArr = array();                      // This array of fields will be set as hidden-fields instead of rendered normally! For instance palette fields edited in the top frame are set as hidden fields since the main form has to submit the values. The top frame actually just sets the value in the main form!
        var $requiredFields=array();                            // Used to register input-field names, which are required. (Done during rendering of the fields). This information is then used later when the JavaScript is made.
+       var $requiredAdditional=array();                        // Used to register input-field names, which are required an have additional requirements (e.g. like a date/time must be positive integer). The information of this array is merged with $this->requiredFields later.
        var $requiredElements=array();                          // Used to register the min and max number of elements for selectorboxes where that apply (in the "group" type for instance)
        var $renderDepth=0;                                                     // Keeps track of the rendering depth of nested records.
        var $savedSchemes=array();                                      // Color scheme buffer.
@@ -1048,7 +1049,6 @@ class t3lib_TCEforms      {
                $size = t3lib_div::intInRange($config['size']?$config['size']:30,5,$this->maxInputWidth);
                $evalList = t3lib_div::trimExplode(',',$config['eval'],1);
 
-
                if($this->renderReadonly || $config['readOnly'])  {
                        $itemFormElValue = $PA['itemFormElValue'];
                        if (in_array('date',$evalList)) {
@@ -1068,6 +1068,13 @@ class t3lib_TCEforms     {
 
                if (in_array('required',$evalList))     {
                        $this->requiredFields[$table.'_'.$row['uid'].'_'.$field]=$PA['itemFormElName'];
+                               // Mark this field for date/time disposal:
+                       foreach ($evalList as $evalItem) {
+                               if ($evalItem == 'date' || $evalItem == 'datetime' || $evalItem == 'time') {
+                                       $this->requiredAdditional[$PA['itemFormElName']]['isPositiveNumber'] = true;
+                                       break;
+                               }
+                       }
                }
 
                $paramsList = "'".$PA['itemFormElName']."','".implode(',',$evalList)."','".trim($config['is_in'])."',".(isset($config['checkbox'])?1:0).",'".$config['checkbox']."'";
@@ -4658,6 +4665,9 @@ class t3lib_TCEforms      {
                                $field = $match[2];
                                $elements[$record][$field]['required'] = 1;
                                $elements[$record][$field]['requiredImg'] = $itemImgName;
+                               if (isset($this->requiredAdditional[$itemName]) && is_array($this->requiredAdditional[$itemName])) {
+                                       $elements[$record][$field]['additional'] = $this->requiredAdditional[$itemName];
+                               }
                        }
                }
                        // range:
index 2b55704..58a0825 100755 (executable)
@@ -77,7 +77,9 @@ function evalFunc_outputObjValue(FObj,value)  {
        var theEvalType = this.split(evallist, ",", index);
        var newValue=value;
        while (theEvalType) {
-               newValue = evalFunc.output(theEvalType, value, FObj);
+               if (theEvalType != 'required') {
+                       newValue = evalFunc.output(theEvalType, value, FObj);
+               }
                index++;
                theEvalType = this.split(evallist, ",", index);
        }
index 0e27ede..d8eb078 100755 (executable)
@@ -44,14 +44,13 @@ var TBE_EDITOR = {
                                        'requiredImg':  ''
                                }
                        }
-               
                },
        */
-       
+
        elements: {},
        recentUpdatedElements: {},
        actionChecks: { submit: [] },
-       
+
        formname: '',
        formnameUENC: '',
        loadTime: 0,
@@ -62,10 +61,10 @@ var TBE_EDITOR = {
        prependFormFieldNames: 'data',
        prependFormFieldNamesUENC: 'data',
        prependFormFieldNamesCnt: 0,
-       
+
        isPalettedoc: null,
        doSaveFieldName: 0,
-       
+
        labels: {},
        images: {
                req: new Image(),
@@ -87,7 +86,7 @@ var TBE_EDITOR = {
        getElement: function(record, field, type) {
                var result = null;
                var element;
-               
+
                if (TBE_EDITOR.elements && TBE_EDITOR.elements[record] && TBE_EDITOR.elements[record][field]) {
                        element = TBE_EDITOR.elements[record][field];
                        if (type) {
@@ -96,7 +95,7 @@ var TBE_EDITOR = {
                                result = element;
                        }
                }
-               
+
                return result;
        },
        checkElements: function(type, recentUpdated, record, field) {
@@ -111,7 +110,7 @@ var TBE_EDITOR = {
                                if (elementData) {
                                        if (!TBE_EDITOR.checkElementByType(type, elementName, elementData)) result = 0;
                                }
-                               
+
                        } else {
                                var elementFieldList, elRecIndex, elRecCnt, elFldIndex, elFldCnt;
                                var elementRecordList = $H(source).keys();
@@ -129,15 +128,16 @@ var TBE_EDITOR = {
                                }
                        }
                }
-               
+
                return result;
        },
        checkElementByType: function(type, elementName, elementData) {
                var result = 1;
-               
+
                if (type) {
                        if (type == 'required') {
-                               if (!document[TBE_EDITOR.formname][elementName].value) {
+                               var value = document[TBE_EDITOR.formname][elementName].value;
+                               if (!value || elementData.additional && elementData.additional.isPositiveNumber && (isNaN(value) || Number(value) <= 0)) {
                                        result = 0;
                                        TBE_EDITOR.setImage('req_'+elementData.requiredImg, TBE_EDITOR.images.req);
                                }
@@ -156,13 +156,13 @@ var TBE_EDITOR = {
                                }
                        }
                }
-               
+
                return result;
        },
        addActionChecks: function(type, checks) {
                TBE_EDITOR.actionChecks[type].push(checks);
        },
-       
+
        // Regular TCEforms JSbottom scripts:
        loginRefreshed: function() {
                var date = new Date();
@@ -224,7 +224,7 @@ var TBE_EDITOR = {
                                TBE_EDITOR.setImage(imgReqObjName,TBE_EDITOR.images.req);
                        }
                }
-               
+
                if (TBE_EDITOR.isPalettedoc) { TBE_EDITOR.setOriginalFormFieldValue(theField) };
        },
        setOriginalFormFieldValue: function(theField) {
@@ -274,7 +274,7 @@ var TBE_EDITOR = {
                if (!TBE_EDITOR.checkElements('required', false)) { OK = 0; }
                // $reqRangeCheck
                if (!TBE_EDITOR.checkElements('range', false)) { OK = 0; }
-                               
+
                if (OK || sendAlert==-1) {
                        return true;
                } else {