Element autocomplete does not validate against list of options

Created on 25 July 2024, 9 months ago

Problem/Motivation

I've got an autocomplete "Countries" that is given a list of options. That all works great, but if I enter some country that doesn't exist in that list, it still submits fine! I chose the 6.3.x version, but this is true of the 6.2.x version as well (which is what I'm actually using).

Steps to reproduce

1. Create a webform element using the "Autocomplete" option
2. On the front end, enter a string into the autocomplete field that does not produce a country match.
3. Submit the form and see no errors. Ideally, it would ask you to choose a valid option.

Proposed resolution

Add a `#element_validate` that checks the submission against the list of valid options. A blank option can be considered valid.

Remaining tasks

Submit an MR -- I will have one up shortly.

πŸ› Bug report
Status

Active

Version

6.3

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States mariacha1

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @mariacha1
  • Status changed to Needs review 9 months ago
  • πŸ‡ΊπŸ‡ΈUnited States mariacha1
  • Pipeline finished with Failed
    9 months ago
    Total: 1965s
    #234164
  • πŸ‡¨πŸ‡¦Canada Liam Morland Ontario, CA πŸ‡¨πŸ‡¦

    Can you add a test for this?

  • πŸ‡¬πŸ‡§United Kingdom mchaplin

    I'm afraid I tried the patch
    https://git.drupalcode.org/issue/webform-3463864/-/commit/a527618b7181cb...
    based on the changes and it failed.

    The issue is that it is taking the input $value (a textual string eg 'location1 from my custom options') and then looking in a keyed array $options[$value] eg $options['location1 from my custom options'] which doesn't exist. It should be eg $options[1] etc.

    So while it prevents the form from submitting if a bad value is entered, it also prevents the form from submitting if a valid option is chosen.

  • First commit to issue fork.
  • Pipeline finished with Failed
    7 months ago
    Total: 1484s
    #291515
  • πŸ‡ΊπŸ‡ΈUnited States jrockowitz Brooklyn, NY

    The autocomplete element is meant to provide suggested values and not be a replacement for a select menu.

  • Pipeline finished with Success
    4 months ago
    Total: 760s
    #373714
  • Pipeline finished with Failed
    4 months ago
    Total: 740s
    #373820
  • Pipeline finished with Skipped
    2 months ago
    #427555
  • πŸ‡¨πŸ‡¦Canada andrew.wang

    I think this has a valid use case - there's a webform on my site that asks the user to select from one of many thousands of species. It doesn't make sense to use a select menu in this case as it'd be a crazy user experience to ask user to choose one from thousands of options from a dropdown menu. Using an autocomplete field with the patch in this issue applied works great for us.

Production build 0.71.5 2024