0

I am using Drupal 8.4.2. I have created my content type and I have an image field in the form fields.

The image upload field is showing on the page but, the upload button is not showing. If I inspect the element, I can see that 'js-hide' class is added for the upload button. I think that is coming from processManagedFile() in core/modules/file/src/Element/ManagedFile.php file.

$element['upload_button'] = [
  '#name' => $parents_prefix . '_upload_button',
  '#type' => 'submit',
  '#value' => t('Upload'),
  '#attributes' => ['class' => ['js-hide']], // Hide class added from here.
  '#validate' => [],
  '#submit' => ['file_managed_file_submit'],
  '#limit_validation_errors' => [$element['#parents']],
  '#ajax' => $ajax_settings,
  '#weight' => -5,
];

It means upload button is hidden in Drupal 8 by default, does it.

If so, after selecting an image, the upload should happen automatically. That is also not happening?

What might be the problem? Is there any setting I need to enable? I would like to have either upload button or the image should be uploaded automatically after selecting an image.

Note

I am having this form for administrator users. Any change must be done in theme, in the specific in the Seven theme.

Update

After selecting an image no ajax request is sent. Do I need to configure ajax upload somewhere in the drupal admin? But after submitting the form, image getting uploaded but showing the alert as "Alternative Text" is mandatory(which was not displayed when uploading the image)

enter image description here

  • 2
    The "js-hide" class hides the submit button when Javascript is enabled. You should be able to upload via AJAX then. Check in the browser debugging tools that the AJAX libraries are loaded and work without errors. – 4k4 Oct 15 at 6:39
  • Did you solve this issue @siddiq – anoopjohn Nov 3 at 1:45
  • @anoopjohn yes, but that is just a work-around. File.js was not included in the admin script. I copied the file.js file in my module and included the js on the admin pages. After that, it is working correctly. I still don't know why the file.js is not included on the admin page. – siddiq Nov 4 at 1:05
  • Do you have custom javascript in your module? You might want to take out all custom javascript and see if that solves the issue as a start. Core javascript should not have issues loading. – anoopjohn Nov 4 at 4:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.