"This Value should not be null" Validation Error With Paragraphs using Media Fields

Created on 4 November 2024, about 2 months ago

Problem/Motivation

There is an issue when using Inline Entity Fields (doesn't seem to matter which kind but I used complex) in a paragraph field attached to a node that has a cardinality greater than one, in which the paragraph (which uses an Inline Entity Form) has a field that has a required media (in my case, image) reference field. If you enter in the required fields, and either try to preview the node, or collapse the paragraph form, an error occurs where EVERY field in the paragraph that contains a media reference will be labelled with an "This Value should not be null" error.

It should be noted this occurs when the form actually should validate. For example, if said paragraph has the media field set as required and you do NOT enter a file for the field, it will correctly display an error on the media field saying that field is required. Its only when all other validation seems to succeed that this particular issue happens. The "This value should not be null" error also seems to appear for every single field, including fields that are not full.

You can see an example of this in the screenshot I uploaded.

Steps to reproduce

I was able to replicate the issue using the following https://simplytest.me/ configuration:

  • Drupal 10.2.9
  • IEF module
  • Field Group Module
  • Paragraphs

Field Group I used to try to get a clean drupal install that is as close to my specific situation as possible. May not be necessary to replicate the issue.

After Installation, log in and then:

  1. Enable Media module
  2. Create new paragraph type with a entity reference to a media item (choose image)
  3. Make this media item required in field settings
  4. Create new content type that has a paragraph field for newly created paragraph type. Choose cardinality of unlimited
  5. Set up form display so the new field is in its own tab (may not be necessary)
  6. Create new node of that type
  7. Add an image paragraph to field. Add everything required.
  8. Click collapse button. The "This value should not be null" error will appear
  9. Clicking the Preview button should also cause this error to happen.

I did research this issue a bit before posting this, there are a couple related issues that seem to cover this, but don't seem to solve the problem, and have a few differences in context that I figured I should create a new issue, especially since most related problems are for different versions. If I was mistaken and should have added to those other issues, please let me know.

🐛 Bug report
Status

Active

Version

3.0

Component

Code

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

Comments & Activities

  • Issue created by @michael.garrido
  • 🇮🇳India debrup

    Working on it.

  • 🇮🇳India debrup

    @michael.garrido In the reproduction steps you mentioned to use media module. However in the screenshot you have used the file upload field for image. Which one should I follow?
    Till now I have not been able to reproduce the error.

    Version info of the modules used:
    - Drupal 10.2.9
    - IEF 3.x (git repo)
    - Field Group 3.6
    - Paragraphs 1.18

  • @debrup Hey, thanks for checking this out! Apologies, that screenshot is from our production set up, and I only included it to show the "Should not by null" error appearing on all the fields. Please follow the reproduction steps in the original post.

    If you still can't reproduce let me know, I will try to reproduce again and create better instructions.

  • 🇮🇳India debrup

    @michael.garrido I still cannot reproduce the error. Please reproduce it from your end again and generate new instructions.

  • Hey @debrup, apologies, I definitely miswrote the instructions as I was writing them. I went through again, and the updated instructions in the OP should now work.

    I was just able to reproduce the issue using Drupal 10.2.9, EIF 3.0.0, and paragraphs 1.17, but I believe the issue is still present up to at least Drupal 10.3.7 (the latest version we are using in production, where the issue still appears).

    for your convenience, I will also copy paste the updated instructions here:

    I was able to replicate the issue using the following https://simplytest.me/ configuration:

    • Drupal 10.2.9 Project
    • IEF module
    • Paragraphs

    After Installation, log in and then:

    1. Enable Media module
    2. Create new paragraph type with a entity reference to a media item (choose image)
    3. Make this media item required in field settings
    4. set the media type to image under the reference type section of field settings.
    5. Go to form display settings for paragraph type. Set The widget of the image field to Inline Entity Form - Complex.
    6. Configure the IEF to have create new revision,. collapsible, and allow users to add new media items set to true
    7. Create new content type and add a field of type paragraphs Choose cardinality of unlimited
    8. Make sure to set the type under reference type to the new paragraph you just created
    9. Set the form display widget of the image paragraphs field to Paragraphs (stable). The default configuration for the widget should be fine.
    10. Create new node of that content type you just created
    11. Upload an image and add alternative text. All required fields for the image should be filled in by doing this.
    12. Click collapse button. The "This value should not be null" error will appear
    13. Clicking the Preview button should also cause this error to happen.
  • 🇮🇳India debrup

    Hi @michael.garrido, just to clarify, are we creating the new media by clicking the "create new media" button before clicking the collapse or preview button?

  • Hey @debrub, no you shouldn't click the create new media button.

  • 🇮🇳India debrup

    Hello @michael.garrido, sorry for the delay in response as I was busy. I was able to reproduce the aforementioned issue successfully. Thank you for providing the revamped instructions. I will be trying to fix the issue.

  • @deprup No worries, no rush on my end as the issue isn't breaking or blocking for our editors. Thank you for taking a look at the issue!

  • 🇮🇳India debrup

    Hello @michael.garrido,
    After a lot of researching I found the main issue is with the paragraphs module and how Drupal does validations by default.

    Whenever a required field is empty or NULL, Drupal Core does not allow the creator to save or preview the node.
    Similarly for paragraphs module, it does not allow any required field to be empty when we are saving or previewing the node or when we try to collapse the field.

    I confirmed this behavior by experimenting with a text field only. There also if the text field was set as required and left empty it will not allow me to collapse the field. Consequently it showed the same "This value should not be null" error.

    Similarly for the media field, unless an until we enter the values and Create the media, the paragraph field is not getting any reference to the media entity. So essentially it is seeing it as a null value in the entity reference field as there is no reference to any entity.

    There is a possible workaround but it is dangerous as it skips the validation process which can cause errors down the line and affect the references which can possibly throw exceptions. However I will suggest some ways to prevent this error.

    • Always create the media before collapsing the field or previewing the node.
    • Make the Media field non-required. This method should be used wisely as the collapsed media is not yet saved and if it is collapsed then data loss may happen and still it has to be created before saving the node.

    Its all I can do for now. Let me know about my analysis and if it is satisfactory or not or in case of any doubts. I will be unassigning myself from the issue for now.

  • @debrup Ah that makes sense. Unfortunately I can't make the media field non required. Instructing our editors to always create the media before collapsing is the most probable work around we will use.

    However, I'm wondering if its possible to automatically save the media entity when collapsing/previewing (or more accurately, before doing so). Does something like that sound feasible? Might not be useful in many cases but in our case it would do.

  • 🇮🇳India debrup

    Hello @michael.garrido, I will try to see if it is possible if I get the time to experiment. But then this issue may get more closer to a "Feature Request" rather than a "Bug Report". Also the changes to be made will act upon core and paragraph functionality albeit through hook implementation. Plus I think the collapse button will require some serious work to achieve what you want (through Javascript).

Production build 0.71.5 2024