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

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

index 5d0f5c9..f3cfe80 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-23  Wolfgang Klinger <wk@plan2.net> 
 
        * Fixed bug #6775: Page and info module ignore "Limit to language"
index f661e19..bcd5ef8 100755 (executable)
@@ -289,6 +289,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.
@@ -1071,7 +1072,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)) {
@@ -1093,6 +1093,10 @@ class t3lib_TCEforms     {
                        switch ($func) {
                                case 'required':
                                        $this->requiredFields[$table.'_'.$row['uid'].'_'.$field]=$PA['itemFormElName'];
+                                               // Mark this field for date/time disposal:
+                                       if (array_intersect($evalList, array('date', 'datetime', 'time'))) {
+                                                $this->requiredAdditional[$PA['itemFormElName']]['isPositiveNumber'] = true;
+                                       }
                                        break;
                                default:
                                        if (substr($func, 0, 3) == 'tx_')       {
@@ -4820,6 +4824,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 41cf7ce..95cb3c9 100755 (executable)
@@ -80,7 +80,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 d0e1fcf..19ee306 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 {