Fixed #11087 and #6372: TCEForm does not replace the existing element if adding a...
authorBenni Mack <benni.mack@typo3.org>
Tue, 19 May 2009 07:42:42 +0000 (07:42 +0000)
committerBenni Mack <benni.mack@typo3.org>
Tue, 19 May 2009 07:42:42 +0000 (07:42 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/branches/TYPO3_4-2@5442 709f56b5-9817-0410-a4d7-c38de5d9e867

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

index 3d92e06..a7dd1fe 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2009-05-19  Benjamin Mack  <benni@typo3.org>
+
+       * Fixed #11087 and #6372: TCEForm does not replace the existing element if adding a new element to a field with maxitems=1
+
 2009-05-19  Francois Suter  <francois@typo3.org>
 
        * Clean up #11118: Reduce memory usage of db_list_extra 
index d1593ca..1015b0e 100755 (executable)
@@ -5240,7 +5240,17 @@ class t3lib_TCEforms     {
                                                        }
                                                }
                                        }
+
                                        if (setOK)      {
+                                                       // remove the existing option element if there is only one element allowed
+                                               var el = TBE_EDITOR.getElementFromFieldName(fName);
+                                               var range = String(el.range);
+                                               range = range.split(",");
+                                               if (range[1] == "1") {
+                                                       setFormValueManipulate(fName, "Remove");
+                                                       len = 0;
+                                               }
+                                               
                                                fObj.length++;
                                                fObj.options[len].value = value;
                                                fObj.options[len].text = unescape(label);
index 03d3234..bf7769c 100755 (executable)
@@ -324,16 +324,21 @@ var TBE_EDITOR = {
                document[TBE_EDITOR.formname][theField].value = RTEcontent;
                alert(document[TBE_EDITOR.formname][theField].value);
        },
+       // strips the "table", the "field" and the "uid" from the fName
+       extractDataFromFieldName: function(fName) {
+               var idx   = 2 + TBE_EDITOR.prependFormFieldNamesCnt;
+               var table = TBE_EDITOR.split(fName, '[', idx);
+               var uid   = TBE_EDITOR.split(fName, '[', idx + 1);
+               var field = TBE_EDITOR.split(fName, '[', idx + 2);
+               return { table: table.substr(0, table.length-1), uid: uid.substr(0, uid.length-1), field: field.substr(0,field.length-1) };
+       },
+       getElementFromFieldName: function(fName) {
+               var data = TBE_EDITOR.extractDataFromFieldName(fName);
+               return TBE_EDITOR.getElement('data[' + data.table + '][' + data.uid + ']', data.field);
+       },
        fieldChanged_fName: function(fName,el) {
-               var idx=2+TBE_EDITOR.prependFormFieldNamesCnt;
-               var table = TBE_EDITOR.split(fName, "[", idx);
-               var uid = TBE_EDITOR.split(fName, "[", idx+1);
-               var field = TBE_EDITOR.split(fName, "[", idx+2);
-
-               table = table.substr(0,table.length-1);
-               uid = uid.substr(0,uid.length-1);
-               field = field.substr(0,field.length-1);
-               TBE_EDITOR.fieldChanged(table,uid,field,el);
+               var data = TBE_EDITOR.extractDataFromFieldName(fName);
+               TBE_EDITOR.fieldChanged(data.table, data.uid, data.field, el);
        },
        fieldChanged: function(table,uid,field,el) {
                var theField = TBE_EDITOR.prependFormFieldNames+'['+table+']['+uid+']['+field+']';