Problem/Motivation

The current autofill functionality allows to exclude certain elements from auto-filling a new submission. This support is only restricted to top-level elements, which means sub-elements in a composite can not be excluded individually. In order to make autofill even more useful, support for excluding specific sub-elements from any composite would be very helpful.

A usage scenario:

  • An 'event_registration' webform, with a composite element for a family group, each composite item including a "confirm" checkbox for final confirmation that the person in that row will participate in the event to which that submission relates.
  • Business requirement: minimize manual steps for users by auto-filling from a previous submission, but requiring that the "confirm" is checked by the user.

Steps to reproduce

N/A

Proposed resolution

  1. Augment the webform_excluded_elements form element, to expose sub-elements from composites, for more fine-grained control.
  2. Update the autofill functionality to properly handle sub-elements selected for exclusion.

Remaining tasks

  1. Implement
  2. Discuss approach, to use constructs/mechanisms native to Webform's architecture (as much as possible).
  3. Review
  4. Write tests

User interface changes

  1. The table-select widget at Settings -> Submissions -> Submission Autofill Settings -> Autofill Elements will now present both the top-level composites, as well as any sub-element for each.

API changes

None (?)

Data model changes

None

Issue fork webform-3239330

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

jedihe created an issue. See original summary.

jedihe’s picture

Issue summary: View changes
Status: Active » Needs review
Issue tags: +Needs tests
StatusFileSize
new2.24 KB

Patch attached; basic testing was done with both a custom composite as well as a 'webform_telephone' composite element.

jrockowitz made their first commit to this issue’s fork.

jrockowitz’s picture

Assigned: Unassigned » jrockowitz
jrockowitz’s picture

Issue tags: -Needs tests

@jedihe Thank you for making the feature request and posting the initial patch.

To make this a fully supported feature, I did some refactoring and added test coverage.

One piece of constructive feedback, PHP array-related methods (i.e. array_walk, array_column, array_keys, array_value, and array_reduce), can make it hard to understand the code compared to simply looping an array and building the desired result. @see WebformExcludedElements::getElements

Changes include...

  • Added #exclude_composite property to WebformExcludedElements
  • Refactored WebformExcludedElements and create WebformExcludedElements::getElements method.
  • Added webform.element.excluded_elements library to style and enhance excluded composite elements.
  • Added support for excluded composites to WebformSubmissionForm
  • Refactored WebformSubmissionForm and created WebformSubmissionForm::getLastSubmissionData
  • Updated WebformElementExcludedElementsTest
  • Updated WebformSettingsAutofillTest

jrockowitz’s picture

Manual steps to review

Add telephone composite to default contact webform

  • /admin/structure/webform/manage/contact

Enable autofill of only the telephone type sub-element

  • /admin/structure/webform/manage/contact/settings/submissions

Generate a test submission

  • /webform/contact/test

Confirm that only the telephone type sub-element is auto filled

  • /form/contact

  • jrockowitz committed f25d6d3 on 6.x
    Issue #3239330 by jrockowitz, jedihe: Autofill: add support for...
jrockowitz’s picture

Status: Needs review » Fixed

I am merging this so that I can address #3239258: Autofill: add support for current/any source entity. If you see any issues please post them here.

Status: Fixed » Closed (fixed)

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

jedihe’s picture

@jrockowitz: thanks so much for pushing this to completion! and thanks for taking the time to provide constructive feedback :).