@johannes-maximilian

Account created on 17 April 2018, over 6 years ago
#

Recent comments

I encountered this problem when creating a custom field widget where managed_file fields along others should be visible according to a select filed. Applying this patch made the whole custom field disappearing because states.js now changed the visibility of the entire fieldset. Because of state.js function $(e.target).closest('.js-form-item, .js-form-submit, .js-form-wrapper').toggle(e.value) the fieldset appeared als closest to the ajax-wrapper element. I discovered, that the upload element didn't had states by default. So for my needs, it was enough to add states to just the upload input element without the ajax wrapper, because states.js can still get the states of these elements and toggle them accordingly. I placed it right below the $element['upload'] definition, to keep it in line. Starting from line 303

        // The file upload field itself.
        $element['upload'] = [
            '#name'             => 'files[' . $parents_prefix . ']',
            '#type'             => 'file',
            '#title'            => t('Choose a file'),
            '#title_display'    => 'invisible',
            '#size'             => $element['#size'],
            '#multiple'         => $element['#multiple'],
            '#theme_wrappers'   => [],
            '#weight'           => -10,
            '#error_no_message' => true,
        ];
        if (!empty($element['#accept'])) {
            $element['upload']['#attributes'] = ['accept' => $element['#accept']];
        }
        // add #states to upload element
        if (isset($element['#states']) && !empty($element['#states'])) {
            $element['upload']['#states'] = $element['#states'];
        }
Production build 0.71.5 2024