[BUGFIX] Get suggest wizard working with renderMode=checkbox 89/18689/7
authorTolleiv Nietsch <info@tolleiv.de>
Wed, 2 May 2012 12:47:17 +0000 (14:47 +0200)
committerWouter Wolters <typo3@wouterwolters.nl>
Thu, 23 Jan 2014 22:42:05 +0000 (23:42 +0100)
In case a select field with renderMode "checkbox" is used together with
the suggest wizard, clicking the suggestions will not check the
related item in the list and therefore the wizard isn't useful anyhow
in that combination.

Fixes: #21924
Releases: 6.2, 6.1, 6.0
Change-Id: I5823197e9f6bb3f3d4ffc4032677478bd18d87f3
Reviewed-on: https://review.typo3.org/18689
Reviewed-by: Markus Klein
Tested-by: Markus Klein
Reviewed-by: Wouter Wolters
Tested-by: Wouter Wolters
typo3/sysext/backend/Classes/Form/Element/SuggestElement.php
typo3/sysext/backend/Classes/Form/FormEngine.php
typo3/sysext/backend/Resources/Public/JavaScript/jsfunc.tceforms_suggest.js

index 59cb92e..959d3a6 100644 (file)
@@ -96,10 +96,17 @@ class SuggestElement {
                        $minChars = intval($config['fieldTSConfig']['suggest.']['default.']['minimumCharacters']);
                }
                $minChars = $minChars > 0 ? $minChars : 2;
+
+               // fetch the TCA field type to hand it over to the JS class
+               $type = '';
+               if (isset($config['fieldConf']['config']['type'])) {
+                       $type = $config['fieldConf']['config']['type'];
+               }
+
                // Replace "-" with ucwords for the JS object name
                $jsObj = str_replace(' ', '', ucwords(str_replace('-', ' ', GeneralUtility::strtolower($suggestId))));
                $this->TCEformsObj->additionalJS_post[] = '
-                       var ' . $jsObj . ' = new TCEForms.Suggest("' . $fieldname . '", "' . $table . '", "' . $field . '", "' . $row['uid'] . '", ' . $row['pid'] . ', ' . $minChars . ');
+                       var ' . $jsObj . ' = new TCEForms.Suggest("' . $fieldname . '", "' . $table . '", "' . $field . '", "' . $row['uid'] . '", ' . $row['pid'] . ', ' . $minChars . ', "' . $type . '");
                        ' . $jsObj . '.defaultValue = "' . GeneralUtility::slashJS($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.findRecord')) . '";
                ';
                return $selector;
index e2a3512..35b90b3 100644 (file)
@@ -563,6 +563,11 @@ class FormEngine {
         */
        protected $multiSelectFilterCount = 0;
 
+       /**
+        * @var \TYPO3\CMS\Backend\Form\Element\SuggestElement
+        */
+       protected $suggest;
+
        // Form templates, relative to typo3 directory
        /**
         * Constructor function, setting internal variables, loading the styles used.
@@ -2131,7 +2136,7 @@ TBE_EDITOR.customEvalFunctions[\'' . $evalData . '\'] = function(value) {
                        }
                }
                // Add an empty hidden field which will send a blank value if all items are unselected.
-               $item .= '<input type="hidden" name="' . htmlspecialchars($PA['itemFormElName']) . '" value="" />';
+               $item .= '<input type="hidden" class="select-checkbox" name="' . htmlspecialchars($PA['itemFormElName']) . '" value="" />';
                // Remaining checkboxes will get their set-all link:
                if (count($setAll)) {
                        $tableHead = '<thead>
@@ -5737,7 +5742,7 @@ TBE_EDITOR.customEvalFunctions[\'' . $evalData . '\'] = function(value) {
                                browserWin.focus();
                        }
                        function setFormValueFromBrowseWin(fName,value,label,title,exclusiveValues) {
-                               var formObj = setFormValue_getFObj(fName), fObj, isMultiple = false, isList = false, len;
+                               var formObj = setFormValue_getFObj(fName), fObj, isMultiple = false, isList = false, isCheckboxList = false, len;
                                if (formObj && value !== "--div--") {
                                                // Check if the form object has a "_list" element or not
                                                // The "_list" element exists for multiple selection select types
@@ -5746,6 +5751,7 @@ TBE_EDITOR.customEvalFunctions[\'' . $evalData . '\'] = function(value) {
                                                isMultiple =  fObj.multiple && fObj.getAttribute("size") != "1";
                                                isList = true;
                                        } else {
+                                               isCheckboxList = formObj[fName].className == "select-checkbox";
                                                fObj = formObj[fName];
                                        }
 
@@ -5809,6 +5815,20 @@ TBE_EDITOR.customEvalFunctions[\'' . $evalData . '\'] = function(value) {
                                                        setHiddenFromList(fObj,formObj[fName]);
                                                        ' . $this->TBE_EDITOR_fieldChanged_func . '
                                                }
+                                       } else if (isCheckboxList) {
+                                               var i=0;
+                                               while (formObj[fName + "[" + i + "]"]) {
+                                                       if (formObj[fName + "[" + i + "]"].value == value) {
+                                                               fObj = formObj[fName + "[" + i + "]"];
+                                                               break;
+                                                       }
+                                                       i++;
+                                               };
+
+                                               if (fObj && !fObj.checked) {
+                                                       fObj.click();
+                                                       ' . str_replace('_list', '', $this->TBE_EDITOR_fieldChanged_func) . '
+                                               }
                                        } else {
                                                        // The incoming value consists of the table name, an underscore and the uid
                                                        // For a single selection field we need only the uid, so we extract it
@@ -5998,6 +6018,7 @@ TBE_EDITOR.customEvalFunctions[\'' . $evalData . '\'] = function(value) {
                                        if (formObj[fName] &&
                                                (
                                                        (formObj[fName].type == "select-one") ||
+                                                       (formObj[fName].className == "select-checkbox") ||
                                                        (formObj[fName + "_list"] && formObj[fName + "_list"].type.match(/select-(one|multiple)/))
                                                )
                                        ) {
index 136afe0..9a40f1b 100644 (file)
@@ -39,6 +39,7 @@ TCEForms.Suggest = Class.create({
        suggestResultList: '',
        minimumCharacters: 2,
        defaultValue: '',
+       fieldType: '',
 
        /**
         * Wrapper for script.aculo.us' Autocompleter functionality: Assigns a new autocompletion object to
@@ -50,12 +51,14 @@ TCEForms.Suggest = Class.create({
         * @param  integer uid       The uid of the record which is currently edited
         * @param  integer pid       The pid of the record which is currently edited
         * @param  integer minimumCharacters the minimum characaters that is need to trigger the initial search
+        * @param  string  fieldType The TCA type of the field (e.g. group, select, ...)
         */
-       initialize: function(objectId, table, field, uid, pid, minimumCharacters) {
+       initialize: function(objectId, table, field, uid, pid, minimumCharacters, fieldType) {
                var PATH_typo3 = top.TS.PATH_typo3 || window.opener.top.TS.PATH_typo3;
                this.objectId = objectId;
                this.suggestField = objectId + 'Suggest';
                this.suggestResultList = objectId + 'SuggestChoices';
+               this.fieldType = fieldType;
 
                new Ajax.Autocompleter(this.suggestField, this.suggestResultList, PATH_typo3 + 'ajax.php', {
                                paramName: 'value',
@@ -97,7 +100,9 @@ TCEForms.Suggest = Class.create({
                        var formEl = this.objectId;
                        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);
+                       var ins_uid_string = (this.fieldType == 'select') ? ins_uid : (ins_table + '_' + ins_uid);
+
+                       setFormValueFromBrowseWin(formEl, ins_uid_string, label);
                        TBE_EDITOR.fieldChanged(rec_table, rec_uid, rec_field, formEl);
 
                        $(this.suggestField).value = this.defaultValue;