Problem/Motivation

We have a contact form with a field that we're prepopulating via URL query/params -- but, when we set a default value for the field, that default value is pre-filled in the field even when the URL has query params meant to pre-fill the field.

I'll paste my webform YML in the first comment, to keep the issue summary clean. Example URL with query:
https://www.example.com/about-us/contact-us?contact=bioinformatics

(So, even with the URL like this and "prepopulate" enabled for the field, the default value, "Communications", is selected every time 😢)


rest of the issue summary template...

Proposed resolution

(Description of the proposed solution, the rationale behind it, and workarounds for people who cannot use the patch.)

Remaining tasks

(reviews needed, tests to be written or run, documentation to be written, etc.)

User interface changes

(New or changed features/functionality in the user interface, modules added or removed, changes to URL paths, changes to user interface text.)

API changes

(API changes/additions that would affect module, install profile, and theme developers, including examples of before/after code if appropriate.)

Data model changes

(Database or configuration data changes that would make stored data on an existing site incompatible with the site's updated codebase, including changes to hook_schema(), configuration schema or keys, or the expected format of stored data, etc.)

Release notes snippet

(Major and critical issues should have a snippet that can be pulled into the release notes when a release is created that includes the fix)

Original report by [username]

(Text of the original report, for legacy issues whose initial post was not the issue summary. Use rarely.)

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

alisonjo315 created an issue. See original summary.

alison’s picture

Issue summary: View changes

Source of form "build":

contact:
  '#type': select
  '#title': 'Who to contact?'
  '#prepopulate': true
  '#options':
    bioinformatics: 'Bioinformatics Facility'
    communications: Communications
    flow-cytometry: 'Flow Cytometry Facility'
    genomics: 'Genomics Facility'
    imaging: 'Imaging Facility'
    metabolomics: 'Metabolomics Facility'
    payment: 'Payment related questions'
  '#required': true
  '#default_value': communications
horizontal_rule1:
  '#type': horizontal_rule
information:
  '#type': section
  '#title': 'Your information'
  '#title_display': invisible
  full_name:
    '#type': textfield
    '#title': 'Full name'
    '#required': true
  email:
    '#type': email
    '#title': Email
    '#required': true
message:
  '#type': textarea
  '#title': Message
  '#required': true
service:
  '#type': entity_select
  '#title': 'Select a service (deprecated)'
  '#description': '<p>If your request relates to a service or product, please select it here.</p>'
  '#disabled': true
  '#access_create_roles': {  }
  '#target_type': node
  '#selection_handler': 'default:node'
  '#selection_settings':
    target_bundles:
      service: service
    sort:
      field: title
      direction: ASC
actions:
  '#type': webform_actions
  '#title': 'Submit button(s)'
  '#submit__label': Submit
alison’s picture

Issue summary: View changes
jrockowitz’s picture

Priority: Normal » Major
FileSize
4.47 KB
560 bytes

The attached webform replicates this issue and the attached patch fixes this issue. The patch still needs test coverage to prevent any additional regressions.

jrockowitz’s picture

Status: Active » Needs review
alison’s picture

Status: Needs review » Reviewed & tested by the community

Holy cow that was crazy fast -- I tried it out and it works PERFECTLY, whether I have the "prepopulate" enabled at the form level or the form field level (yay!).

👍⭐️

jrockowitz’s picture

Status: Reviewed & tested by the community » Needs work

You can use the patch AS-IS but I still need to improve the test coverage to prevent this type of regression.

jrockowitz’s picture

Status: Needs work » Needs review
FileSize
6.98 KB

This patch has better test coverage.

  • jrockowitz authored a9be577 on 8.x-5.x
    Issue #3122362 by jrockowitz: Default field value supersedes prepopulate...
jrockowitz’s picture

Status: Needs review » Postponed

Since the patch has even more test coverage, I committed it. Please download the latest dev release to review.

jrockowitz’s picture

Status: Postponed » Fixed
alison’s picture

Thank you!

Status: Fixed » Closed (fixed)

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