Validation error on collapsed paragraph <field_name>: This value should not be null.

Created on 15 November 2022, about 2 years ago
Updated 29 July 2024, 4 months ago

Problem/Motivation

The error happens when the paragraph has a required but disabled(hidden) field and it's collapsed.

P.S. The issue looks like duplicate of the πŸ› Closed paragraph validation error: This value should not be null Closed: outdated but it's not.

Steps to reproduce

Quick reproduce:

  • Make a paragraph with required field + some non required field/fields
  • Go to the form display and disable the required field.
  • Make a new content type with Paragraph field
  • Create a new node of the new content type + add the new paragraph type to the content field
  • Fill in visible fields and collapse the paragraph
  • Press Save the content

Real case:

  • We have a paragraph with the required field
  • The paragraph has two form displays: on the first one the required field is disabled and enabled on the second one
    • PA: the required field is disabled
    • PB: the required field is enabled
  • We have two content types where:
    • CA: use paragraph with form display PA - means that required field is hidden and isn't used for this content type
    • CB: use paragraph with form display PB - means that required field exists on the form and required for filling
  • Result when we save the content with the collapsed paragraph:
    • CA: Error "Validation error on collapsed paragraph : This value should not be null."
    • CB: works es expected

Proposed resolution

We need to exclude hidden fields from the validation.

πŸ› Bug report
Status

Fixed

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡¦Ukraine HitchShock Ukraine

Live updates comments and jobs are added and updated live.
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.

  • πŸ‡ΊπŸ‡ΈUnited States neclimdul Houston, TX

    Looking at the patch, it looks like it filters out all validations from hidden fields. That doesn't seem like a good thing, we should still want validation of hidden fields. If I'm miss-reading it could we can add a comment to the code explaining why its ok to filter them?

  • πŸ‡ΊπŸ‡¦Ukraine HitchShock Ukraine

    @neclimdul cuz this is normal Drupal behavior to not validate hidden fields on entity form. You can check this by you self:
    - add required field to the node
    - hide it on the entity form
    - on node save action you should not see the error that field is empty
    - when the field is visible you will see an error

    This is an expected behavior.

    Paragraph breaks this logic when it's collapsed. But works well when it's expanded.
    So we need to fix this behaviour for the collapsed paragraph case.

  • Status changed to RTBC about 1 year ago
  • πŸ‡΅πŸ‡°Pakistan monymirza Islamabad

    #4 RTBC+1

  • πŸ‡¨πŸ‡­Switzerland berdir Switzerland

    Committed, agreed that this makes sense.

  • Status changed to Fixed 10 months ago
  • Automatically closed - issue fixed for 2 weeks with no activity.

  • πŸ‡ΊπŸ‡ΈUnited States kescoto-thinkshout

    Has anyone else continued to see this issue? We are still encountering this error even though we have the latest version of the module.

  • I agree, the error is still occurring even with the patch applied, any updates on this case ?

  • πŸ‡¦πŸ‡«Afghanistan drupalam

    This issue should be fixed if you update to version 1.17.

     $violations = $paragraphs_entity->validate();
              $violations->filterByFieldAccess();
              $hidden_fields = (array) $display->get('hidden');
              $violations->filterByFields(array_keys($hidden_fields));
Production build 0.71.5 2024