Duplicate values not removed before saving field

Created on 29 December 2021, about 3 years ago
Updated 8 June 2023, over 1 year ago

Problem/Motivation

If a value entered in the "Other" area duplicates a value already stored in the field, duplicate values get stored in the database. The problem is particularly likely to come up with fields with longer option lists and/or when this module is used in conjunction with Chosen module to create a "free tagging" style interface.

Steps to reproduce

  1. Create a "list" field (text or integer) and allow multiple values. Example: "favorite colors"
  2. Create an allowed values list. Example: "Red, Green, Blue"
  3. Configure field to use Select or Other.
  4. Create a test node. Select one or more of the allowed values ("Green") AND select the "Other" option.
  5. In the "other" field, enter one of the selected, existing values ("Green").
  6. Save and view the node. The value entered in "Other" field ("Green") is now displayed twice.

Proposed resolution

Add code to remove duplicate values. The attached patch uses array_unique and seems to fix the problem for text and integer fields.

Remaining tasks

  • Confirm the behavior produced by this change is desired: duplicate entries should not be created.
  • Patch needs review and testing.
  • Consider if the code that removes duplicates should be case-sensitive or not. It is currently case-sensitive, so in the above example "green" would be allowed as a new entry but "Green" would be considered a duplicate.
🐛 Bug report
Status

Needs review

Version

4.0

Component

Code

Created by

🇺🇸United States isaac77

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.

  • 🇮🇳India nikhil_110

    I implemented patch on my local machine using Drupal 9.5 with Select (or other) v4.x-dev. It is working properly..
    I have added the test steps and Attaching the screenshot for reference.Please review.

    • Setup Drupal with Select (or other) v4.x-dev
    • Enabled Select (or other)
    • Go to Admin > Structure > Content Types > Basic Page > Add New field List (text).
    • Go to Admin > Structure > Content Types > Basic Page > Manage form display > Go to List field and Chose Select or Other select list .
    • Go to Admin > Add content > Create new node by selecting Color name and with other options
Production build 0.71.5 2024