How to display a field when a media is uploaded to the media library field? I have block settings form where I have a media library field.
 public function blockForm($form, FormStateInterface $form_state) {
    $form = parent::blockForm($form, $form_state);
    $user_input = $form_state-&gt;getUserInput();
    $my_field = $user_input['settings']['my_field'] ?? $this-&gt;configuration['my_field'] ?? NULL;

    $form['my_field'] = [
      '#type' =&gt; 'media_library',
      '#allowed_bundles' =&gt; ['my_bundle'],
      '#title' =&gt; $this-&gt;t('Upload'),
      '#default_value' =&gt; $this-&gt;configuration['my_field'] ?? '',
      '#required' =&gt; TRUE,
      '#ajax' =&gt; [
        'callback' =&gt; [$this, 'ajaxCallback'],
        'event' =&gt; 'updateMediaLibrarySelection'
        'wrapper' =&gt; 'test-field',
      ],
    ];

    $form['test'] = [
      '#type' =&gt; 'textfield',
      '#title' =&gt; 'test',
      '#prefix' =&gt; '&lt;div id=&quot;test-field&quot;&gt;',
      '#suffix' =&gt; '&lt;/div&gt;',
    ];

    if (empty($my_field)) {
      $form['test']['#wrapper_attributes']['class'][] = 'visually-hidden';
    }

    return $form;
  }

  



public function ajaxCallback(array &amp;$form, FormStateInterface $form_state): array {
    return $form['settings']['test'];
  }

but my ajaxCallback method never called and the test field is always hidden.
I did with javascript because the field type media_library is not an actual input field.
I overrided the setMediaUploadFieldValue jQuery function of the media_library_form_element module.
(($, Drupal) =&gt; {
  Drupal.behaviors.VideoComponent = {
    attach: () =&gt; {
      $.fn.setMediaUploadFieldValue = (data, element) =&gt; {
        const mediaElement = document.querySelector(element);
        const currentValue = mediaElement.value;

        mediaElement.value = `${currentValue}${
          currentValue === &quot;&quot; ? &quot;&quot; : &quot;,&quot;
        }${data}`;

        try {
          fetch(`${my_url}`)
            .then(response =&gt; response.json())
            .then(result =&gt; {
              if (result) {
                // Do something
              }
            });
        } catch (error) {
          return false;
        }
      };
    }
  };
})(jQuery, Drupal);