Created exclusiveKeys for the TCA field configuration of type "select". Changelog...
authorMartin Kutschker <martin.t.kutschker@blackbox.net>
Thu, 22 Jun 2006 13:12:16 +0000 (13:12 +0000)
committerMartin Kutschker <martin.t.kutschker@blackbox.net>
Thu, 22 Jun 2006 13:12:16 +0000 (13:12 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@1522 709f56b5-9817-0410-a4d7-c38de5d9e867

ChangeLog
t3lib/class.t3lib_tceforms.php
t3lib/class.t3lib_tcemain.php

index 39834fe..082fce5 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+
+2006-06-22  Martin Kutschker  <martin.t.kutschker@blackbox.net>
+
+       * Created exclusiveKeys for the TCA field configuration of type "select" [fix from 2006-03-19 was lost, see below]
+
 2006-06-11  Stanislas Rolland  <stanislas.rolland@fructifor.ca>
 
        * Fix bugtracker issue 3505: BE multi-language flexforms do not work (t3lib_tceforms)
index fbae6e9..0afdb96 100755 (executable)
@@ -1732,7 +1732,12 @@ class t3lib_TCEforms     {
                        $selector_itemListStyle = isset($config['itemListStyle']) ? ' style="'.htmlspecialchars($config['itemListStyle']).'"' : ' style="'.$this->defaultMultipleSelectorStyle.'"';
                        $size = intval($config['size']);
                        $size = $config['autoSizeMax'] ? t3lib_div::intInRange(count($itemArray)+1,t3lib_div::intInRange($size,1),$config['autoSizeMax']) : $size;
-                       $sOnChange = 'setFormValueFromBrowseWin(\''.$PA['itemFormElName'].'\',this.options[this.selectedIndex].value,this.options[this.selectedIndex].text); '.implode('',$PA['fieldChangeFunc']);
+                       if ($config['exclusiveKeys'])   {
+                               $sOnChange = 'setFormValueFromBrowseWin(\''.$PA['itemFormElName'].'\',this.options[this.selectedIndex].value,this.options[this.selectedIndex].text,\''.$config['exclusiveKeys'].'\'); ';
+                       } else {
+                               $sOnChange = 'setFormValueFromBrowseWin(\''.$PA['itemFormElName'].'\',this.options[this.selectedIndex].value,this.options[this.selectedIndex].text); ';
+                       }
+                       $sOnChange .= implode('',$PA['fieldChangeFunc']);
                        $itemsToSelect = '
                                <select name="'.$PA['itemFormElName'].'_sel"'.
                                                        $this->insertDefStyle('select').
@@ -4789,24 +4794,40 @@ class t3lib_TCEforms    {
                                browserWin = window.open(url,"Typo3WinBrowser","height=350,width="+(mode=="db"?650:600)+",status=0,menubar=0,resizable=1,scrollbars=1");
                                browserWin.focus();
                        }
-                       function setFormValueFromBrowseWin(fName,value,label)   {       //
+                       function setFormValueFromBrowseWin(fName,value,label,exclusiveValues)   {       //
                                var formObj = setFormValue_getFObj(fName)
                                if (formObj && value!="--div--")        {
                                        fObj = formObj[fName+"_list"];
+                                       var len = fObj.length;
+                                               // Clear elements if exclusive values are found
+                                       if (exclusiveValues)    {
+                                               var m = new RegExp("(^|,)"+value+"($|,)");
+                                               if (exclusiveValues.match(m))   {
+                                                               // the new value is exclusive
+                                                       for (a=len-1;a>=0;a--)  fObj[a] = null;
+                                                       len = 0;
+                                               } else if (len == 1)    {
+                                                       m = new RegExp("(^|,)"+fObj.options[0].value+"($|,)");
+                                                       if (exclusiveValues.match(m))   {
+                                                                       // the old value is exclusive
+                                                               fObj[0] = null;
+                                                               len = 0;
+                                                       }
+                                               }
+                                       }
                                                // Inserting element
-                                       var l=fObj.length;
-                                       var setOK=1;
+                                       var setOK = 1;
                                        if (!formObj[fName+"_mul"] || formObj[fName+"_mul"].value==0)   {
-                                               for (a=0;a<l;a++)       {
+                                               for (a=0;a<len;a++)     {
                                                        if (fObj.options[a].value==value)       {
-                                                               setOK=0;
+                                                               setOK = 0;
                                                        }
                                                }
                                        }
                                        if (setOK)      {
                                                fObj.length++;
-                                               fObj.options[l].value=value;
-                                               fObj.options[l].text=unescape(label);
+                                               fObj.options[len].value = value;
+                                               fObj.options[len].text = unescape(label);
 
                                                        // Traversing list and set the hidden-field
                                                setHiddenFromList(fObj,formObj[fName]);
index 626cbbe..8cb5e39 100755 (executable)
@@ -1266,7 +1266,7 @@ class t3lib_TCEmain       {
 
                list($table,$id,$curValue,$status,$realPid,$recFID) = $PP;
 
-                       // Detecting if value send is an array and if so, implode it around a comma:
+                       // Detecting if value sent is an array and if so, implode it around a comma:
                if (is_array($value))   {
                        $value = implode(',',$value);
                }
@@ -1275,7 +1275,7 @@ class t3lib_TCEmain       {
                        // Anyways, this should NOT disturb anything else:
                $value = $this->convNumEntityToByteValue($value);
 
-                       // When values are send as group or select they come as comma-separated values which are exploded by this function:
+                       // When values are sent as group or select they come as comma-separated values which are exploded by this function:
                $valueArray = $this->checkValue_group_select_explodeSelectGroupValue($value);
 
                        // If not multiple is set, then remove duplicates:
@@ -1283,7 +1283,18 @@ class t3lib_TCEmain      {
                        $valueArray = array_unique($valueArray);
                }
 
-               // This could be a good spot for parsing the array through a validation-function which checks if the values are allright (except that database references are not in their final form - but that is the point, isn't it?)
+                       // If an exclusive key is found, discard all others:
+               if ($tcaFieldConf['type']=='select' && $tcaFieldConf['exclusiveKeys'])  {
+                       $exclusiveKeys = t3lib_div::trimExplode(',', $tcaFieldConf['exclusiveKeys']);
+                       foreach($valueArray as $kk => $vv)      {
+                               if (in_array($vv, $exclusiveKeys))      {       // $vv is the item key!
+                                       $valueArray = Array($kk => $vv);
+                                       break;
+                               }
+                       }
+               }
+
+               // This could be a good spot for parsing the array through a validation-function which checks if the values are alright (except that database references are not in their final form - but that is the point, isn't it?)
                // NOTE!!! Must check max-items of files before the later check because that check would just leave out filenames if there are too many!!
 
                        // Checking for select / authMode, removing elements from $valueArray if any of them is not allowed!