[BUGFIX] Use `find()` to get option tags from select 09/48209/2
authorAndreas Fernandez <a.fernandez@scripting-base.de>
Mon, 9 May 2016 15:04:25 +0000 (17:04 +0200)
committerMarkus Klein <markus.klein@typo3.org>
Wed, 18 May 2016 12:43:07 +0000 (14:43 +0200)
Using `children()` to get the option tags from the select fields
will fail if the select field contains `optgroup` tags (e.g. rendered
by a hook).

This patch replaces `children()` with `find()` to cover this
edge case.

Resolves: #76097
Releases: master, 7.6
Change-Id: Ib80f422d465d9e48232b1820e524a01a97eb94e6
Reviewed-on: https://review.typo3.org/48209
Reviewed-by: Markus Klein <markus.klein@typo3.org>
Tested-by: Markus Klein <markus.klein@typo3.org>
typo3/sysext/backend/Resources/Public/JavaScript/FormEngine.js

index bbdcb78..c6d0ed3 100644 (file)
@@ -137,9 +137,9 @@ define(['jquery',
                                if (exclusiveValues.match(m)) {
                                        $fieldEl.empty();
                                        reenableOptions = true;
-                               } else if ($fieldEl.children('option').length == 1) {
+                               } else if ($fieldEl.find('option').length == 1) {
                                        // there is an old value and it was exclusive => it has to be removed
-                                       m = new RegExp("(^|,)" + $fieldEl.children('option').prop('value') + "($|,)");
+                                       m = new RegExp("(^|,)" + $fieldEl.find('option').prop('value') + "($|,)");
                                        if (exclusiveValues.match(m)) {
                                                $fieldEl.empty();
                                                reenableOptions = true;
@@ -157,7 +157,7 @@ define(['jquery',
                        // check if there is a "_mul" field (a field on the right) and if the field was already added
                        var $multipleFieldEl = FormEngine.getFieldElement(fieldName, '_mul', true);
                        if ($multipleFieldEl.length == 0 || $multipleFieldEl.val() == 0) {
-                               $fieldEl.children('option').each(function(k, optionEl) {
+                               $fieldEl.find('option').each(function(k, optionEl) {
                                        if ($(optionEl).prop('value') == value) {
                                                addNewValue = false;
                                                return false;
@@ -212,7 +212,7 @@ define(['jquery',
         */
        FormEngine.updateHiddenFieldValueFromSelect = setHiddenFromList = function(selectFieldEl, originalFieldEl) {
                var selectedValues = [];
-               $(selectFieldEl).children('option').each(function() {
+               $(selectFieldEl).find('option').each(function() {
                        selectedValues.push($(this).prop('value'));
                });