Issue Bug Closed

#82179FormEngine triggers link explanation when new links are created, when it shouldn't

Johannes Schlier 08/23/17, 16:30 updated 10/02/18, 10:56

Description

If there are links on a backend form they are correctly initialised by FormEngine.js with the following code on lines 1005-1022:

    FormEngine.initializeInputLinkToggle = function() {
        var toggleClass = '.t3js-form-field-inputlink-explanation-toggle',
            inputFieldClass = '.t3js-form-field-inputlink-input',
            explanationClass = '.t3js-form-field-inputlink-explanation';

        // if empty, show input field
        $(explanationClass).filter(function () {
            return !$.trim($(this).val());
        }).each(function () {
            var $group = $(this).closest('.t3js-form-field-inputlink'),
                $inputField = $group.find(inputFieldClass),
                $explanationField = $group.find(explanationClass),
                explanationShown;
            explanationShown = !$explanationField.hasClass('hidden');
            $explanationField.toggleClass('hidden', explanationShown);
            $inputField.toggleClass('hidden', !explanationShown);
            $group.find('.form-control-clearable button.close').toggleClass('hidden', !explanationShown)
        });

This works correctly the first time, but if a new link is created, as an IRRE element for example, the same code is executed again.
This means that the line

            explanationShown = !$explanationField.hasClass('hidden');

gives a different result and all link fields that are empty (or not empty, but not yet saved), are triggered again, even though they shouldn’t. This leads to the empty explanation field being shown, which cannot be triggered to the input field again.
Creating another link after this triggers them again with the same result as the first time – with the input field shown, not the explanation field. And so on …

Reviews 2