Media library does not show Alternative text field as required when using Decorative image widget

Created on 9 February 2023, over 1 year ago
Updated 8 October 2023, 9 months ago

Problem/Motivation

When using the Decorative image widget in the Media library view mode, the Alternative text field is not correctly marked as required when the Decorative checkbox is unselected.

It prevents from submitting the form but does not give the user any input how to fix the problem.

Steps to reproduce

Create a new Media library field in a content type and mark the Force image to be marked decorative if no alt text provided as checked in the view mode.

When trying to submit a new media item in the media library view mode, the alternative text is not marked as required and it prevents the form from being submitted.

It allows you to save the form when you first check the Decorative checkbox but this isn't obvious to the end user

Proposed resolution

Add the normal required attribute and asterix to the alternative text field.

Tested with Gin and Claro admin themes and Drupal 9.5.2.

🐛 Bug report
Status

Fixed

Version

1.0

Component

Code

Created by

🇫🇮Finland HeikkiY Oulu

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @HeikkiY
  • 🇫🇮Finland HeikkiY Oulu

    I debugged the problem a bit and it seems like the module is adding a custom validation message here: https://git.drupalcode.org/project/decorative_image_widget/-/blob/1.0.x/...

    This does not seem to get triggered with the Ajax form in the media library modal.

    Also it seems like the field is still marked as optional in both places (/media/add/image and media library modal). You do get an error message when trying to submit the form without alternative text but I think both fields should have the required asterix indicator also when no alternative text is provided and the decorative image checkbox is unchecked.

  • 🇫🇮Finland HeikkiY Oulu

    To add to this issue, there is a second UX problem because currently the help text for alternative text says:
    Short description of the image used by screen readers and displayed when the image is not loaded. This is important for accessibility. If alternative text is not applicable, leave this field empty.

    This is a bit confusing because the user needs to try and submit the form before there is any indication that the alternative text is required.

  • @heikkiy opened merge request.
  • 🇫🇮Finland HeikkiY Oulu

    I added the following patch to the issue:

    1. It improves the description text for the Alternative text to take into account the new checkbox.
    2. It adds new functionality to the JS which first of all triggers the alternative text as required based on the checkbox and also marks the label field as required to add the Drupal required ::after element to it.

  • Status changed to Needs review about 1 year ago
  • Status changed to Needs work about 1 year ago
  • 🇺🇸United States Luke.Leber Pennsylvania
  • 🇫🇮Finland HeikkiY Oulu

    @lukeleber

    I understand what you mean and I agree on the part that it's not on the scope of the issue. I would still argue that it would be also better to improve the alternative text also. We have had some feedback from our clients that they do not understand the setting.

    I will update the ticket description and title to take those into account.

  • Status changed to Needs review about 1 year ago
  • Status changed to RTBC about 1 year ago
  • 🇺🇸United States Luke.Leber Pennsylvania

    The JS changes in !2 look good - manually tested against 9.4.x + Claro and 9.4.x + Gin and the required-ness looks and feels like other required fields when the decorative checkbox is unticked.

    +1 RTBC.

  • 🇬🇧United Kingdom aaron.ferris

    Thanks for this patch, I've just pulled this module down and was noticing this exact behaviour which is a potential UX problem. Works well and applies cleanly to 1.0.0-alpha4. +1 for this patch!

  • Status changed to Fixed 9 months ago
  • 🇺🇸United States bkosborne New Jersey, USA

    Looks good. Tested this with Drupal 10.1 using Claro, both when uploading an image via the media library and when doing it directly from a media add form.

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.69.0 2024