Empty collections will not validate on required fields

Created on 3 November 2020, over 3 years ago
Updated 30 January 2023, over 1 year ago

Problem/Motivation

When having, for example multiple textfields, in a single collection which are all / partly required, and is submitted with none of them filled the module will not validate the form for the any of the required fields in the collection.

Steps to reproduce

  1. Create a field collection with, say 5 textfields, all required.
  2. Submit a form with this collection, leave all fields empty.
  3. Note that the form will never complain about any of the fields being empty.
  4. Try re-submitting the form, but now fill one of the 5 fields.
  5. Note that now the form will actually validate the requirements and give errors.

Proposed resolution

Leave out the !field_collection_item_is_empty($field_collection_item) from the if statement on field_collection.module:1775.

Remaining tasks

I'll submit a patch.

User interface changes

None

API changes

None

Data model changes

None

πŸ› Bug report
Status

Needs review

Version

1.0

Component

Code

Created by

πŸ‡³πŸ‡±Netherlands nielsva

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.

  • πŸ‡§πŸ‡ΎBelarus drupalprojects

    Guys, the fix doesn't work properly. I've installed latest 7.x-1.x-dev version and one of my users complained that he cannot save a form anymore. The form has a field_collection item (non-mandatory itself) with 2 mandatory fields inside the collection.
    I assume that if a field collection is not marked as mandatory - I should be able to save the form without adding any values to it. So with this patch applied - it didn't work properly and it took me years to find a root cause for that.
    Once I added the check for if (!empty($element['#field_collection_required_elements']) && !field_collection_item_is_empty($field_collection_item)) on line 1788 of field_collection.module - it is working properly now.

    By the way, I have another field_collection item on the same node which is mandatory and with my fix it is still validating that other mandatory field properly.

  • Status changed to Needs review over 1 year ago
  • πŸ‡ͺπŸ‡ͺEstonia ram4nd Tallinn
Production build 0.69.0 2024