[BUGFIX] Select label element from suggest-list 69/20069/2
authorStefan Neufeind <typo3.neufeind@speedpartner.de>
Sat, 20 Apr 2013 19:43:16 +0000 (21:43 +0200)
committerOliver Hader <oliver.hader@typo3.org>
Mon, 22 Apr 2013 13:13:39 +0000 (15:13 +0200)
If a sprite is the first child in chosen item from
suggest-list no label is generated.

Therefore select the element depending on the class.
Besides that, e.g. Flexform elements use "invalid" CSS
IDs that contain "[" and "]" characters - using plain
CSS selectors on that does not work and needs to be
escaped first.

Fixes: #47409
Releases: 4.5, 4.7, 6.0, 6.1
Change-Id: I40fad4b6596923cc87889726794f115eb7b58eb5
Reviewed-on: https://review.typo3.org/20069
Reviewed-by: Oliver Hader
Tested-by: Oliver Hader
t3lib/js/jsfunc.tceforms_suggest.js

index 1aa216d..0f59806 100644 (file)
@@ -95,11 +95,27 @@ TCEForms.Suggest = Class.create({
                        var rec_field = arr[4];
 
                        var formEl = 'data[' + rec_table + '][' + rec_uid + '][' + rec_field + ']';
-                       var label = (item.firstChild.textContent ? item.firstChild.textContent : item.firstChild.innerText)
+                       var suggestLabelNode = Element.select(this.escapeObjectId(item.id), '.suggest-label')[0];
+                       var label = (suggestLabelNode.textContent ? suggestLabelNode.textContent : suggestLabelNode.innerText)
                        setFormValueFromBrowseWin(formEl, ins_table + '_' + ins_uid, label);
                        TBE_EDITOR.fieldChanged(rec_table, rec_uid, rec_field, formEl);
 
                        $(this.suggestField).value = this.defaultValue;
                }
+       },
+
+       /**
+        * Escapes object identifiers of e.g. Flexform CSS IDs
+        *
+        * @param string objectId
+        * @return string
+        */
+       escapeObjectId: function(objectId) {
+               var escapedObjectId;
+               escapedObjectId = objectId.replace(/:/g, '\\:');
+               escapedObjectId = objectId.replace(/\./g, '\\.');
+               escapedObjectId = objectId.replace(/\[/g, '\\[');
+               escapedObjectId = objectId.replace(/\]/g, '\\]');
+               return escapedObjectId;
        }
 });