Media Library widget produces "This value should not be null" error when field is required

Created on 20 July 2020, almost 4 years ago
Updated 2 May 2023, about 1 year ago

Problem/Motivation

If you have a required media field that uses the core media library, and you try to submit it without any values, you get a really unclear error message: "This value should not be null". It offers no clues whatsoever concerning which field it's even talking about. This is pretty bad for UX.

Steps to reproduce

Create a media field on a node type, ensuring it uses the media library and requires at least one selection. Go to create a new node of that type, and submit it without selecting any media. You'll get the world's least helpful error message.

Proposed resolution

Implement a custom validation method, so as to produce a better error. This cannot be done using the Form API's #required property, because the media library widget is a composite field type that persists information around in hidden fields that change during user interaction.

Remaining tasks

Commit the merge request.

User interface changes

When submitting an empty, required media library field, users will get a useful error message, instead of a worthless one.

API changes

None.

Data model changes

None.

Release notes snippet

None needed.

🐛 Bug report
Status

Fixed

Version

9.2

Component
Media 

Last updated about 16 hours ago

Created by

🇮🇳India chandu7929 Pune

Live updates comments and jobs are added and updated live.
  • Usability

    Makes Drupal easier to use. Preferred over UX, D7UX, etc.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.69.0 2024