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 #3030966: Closed paragraph validation error: This value should not be null 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.

Issue fork paragraphs-3321404

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

    Comments

    HitchShock created an issue. See original summary.

    hitchshock’s picture

    Issue summary: View changes
    hitchshock’s picture

    Status: Active » Needs review
    StatusFileSize
    new840 bytes
    hitchshock’s picture

    StatusFileSize
    new848 bytes
    deepalij’s picture

    StatusFileSize
    new74.18 KB

    Applied patch #4 on Drupal 10.1.x-dev
    Patch applied cleanly
    Able to reproduce the issue
    The issue got fixed. "Validation error on collapsed paragraph : This value should not be null." is not appearing after applying the patch and getting a success message.

    RTBC+1

    deepalij’s picture

    neclimdul’s picture

    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?

    hitchshock’s picture

    @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 for UI

    Paragraph breaks this logic when it's collapsed. But works well when it's expanded.
    So we need to fix UI behaviour for the collapsed paragraph case.
    Fix was applied to the field widget, it means that only UI behaviour has been fixed. Which is ok.

    monymirza’s picture

    Status: Needs review » Reviewed & tested by the community

    #4 RTBC+1

    berdir’s picture

    Status: Reviewed & tested by the community » Fixed

    Committed, agreed that this makes sense.

    • Berdir committed 4006a90f on 8.x-1.x authored by HitchShock
      Issue #3321404 by HitchShock: Validation error on collapsed paragraph...

    Status: Fixed » Closed (fixed)

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

    kescoto-thinkshout’s picture

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

    meryem dibe’s picture

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

    drupalam’s picture

    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));