Problem/Motivation

Possibly a feature request instead of a bug report. We are encountering the following scenario:

  1. Add a composite element.
  2. Mark an individual field inside it required.
  3. Limit to 3 allowed values.

The user is required to fill all three rows, instead of up to three rows.

Screenshot and sample webform:

test_composite:
  '#type': custom_composite
  '#title': 'Test Composite'
  '#required': true
  '#multiple': 3
  '#element':
    foo:
      '#type': textfield
      '#title': 'Foo (required)'
      '#required': true
    bar:
      '#type': textfield
      '#title': 'Bar (optional)'

Proposed resolution

There could be a few ways to address this. Some possible solutions:

  • Fields are only validated as required for rows in a composite that are not empty.
  • The "Limit" setting could work the same as "Unlimited", but the "Add another" button is hidden once the limit is reached.

Comments

Sam152 created an issue. See original summary.

jrockowitz’s picture

Personally, I use the limit to show all the available rows so that the user does not have to keep clicking 'Add more'.

I like...

Fields are only validated as required for rows in a composite that are not empty.

vierlex’s picture

There should be both options I guess.
But I personally would use only the second option.

Since in case for composites (lets say, 7 fields) which you want to have, say, 10 maximum,
Displaying all 10x7 is way too much.

jrockowitz’s picture

StatusFileSize
new5.27 KB

The attached patch stops defaulting the displayed number of items to match the cardinality.

If someone wants the displayed number of items to match the cardinality they can set the #min_items.

jrockowitz’s picture

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, 4: 2984983-4.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

jrockowitz’s picture

Status: Needs work » Needs review
StatusFileSize
new9.56 KB

Status: Needs review » Needs work

The last submitted patch, 7: 2984983-7.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

vierlex’s picture

Wow so cool! I will test it right away

jrockowitz’s picture

Status: Needs work » Needs review
StatusFileSize
new9.56 KB
jrockowitz’s picture

StatusFileSize
new10.14 KB

This patch makes sure min items and empty item don't exceed the cardinality.

  • jrockowitz committed 1153746 on 8.x-5.x
    Issue #2984983 by jrockowitz: Required fields inside a composite are...
jrockowitz’s picture

Status: Needs review » Fixed

I committed the patch. Please download the latest dev release to review.

Here is the change record.

Status: Fixed » Closed (fixed)

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