Skip to content

Fix optional dropdown auto-selecting the first value - #2973

Open
RabbiIslamRony wants to merge 2 commits into
developmentfrom
investigate-ticket-3246
Open

Fix optional dropdown auto-selecting the first value#2973
RabbiIslamRony wants to merge 2 commits into
developmentfrom
investigate-ticket-3246

Conversation

@RabbiIslamRony

Copy link
Copy Markdown
Member

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Security fix
  • Improvement
  • New Feature
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • Text changes
  • Other... Please describe:

Description

Main issue

An optional custom Dropdown rendered only its configured choices. When a new listing or an imported listing had no saved value for that field, the browser automatically selected the first choice because the <select> had no empty option. Saving the form could then store that first choice even though the user never selected it.

The CSV importer itself does not assign the first choice for an empty cell; the unintended value came from the dropdown's rendered default state when the listing was later edited and saved.

Solution

  • Add an empty Select... option to optional custom Dropdown fields.
  • Use the configured field placeholder when one exists.
  • Preserve the selected state for listings that already have a saved value.
  • Avoid adding a second empty option when the field already defines one.
  • Keep required Dropdown behavior unchanged.

Easy test cases

  1. Add an optional custom Dropdown with New and Used choices, then open the Add Listing form. Confirm Select... is selected by default.
  2. Save the listing without choosing a value. Confirm the field remains empty and is not shown as New on the listing.
  3. Select Used, save, and reopen the listing. Confirm Used remains selected.
  4. Import a listing with the Dropdown CSV cell empty, then edit and save it without choosing a value. Confirm the field remains empty.
  5. Make the Dropdown required. Confirm its existing behavior is unchanged and no empty option is added.
  6. Configure an empty option manually. Confirm only one empty option appears.

Verification performed

  • PHP syntax check
  • PHPCS on the changed template
  • PHP 8.1+ compatibility check on the changed template
  • Runtime rendering checks for empty, saved, required, existing-empty, and custom-placeholder cases
  • Runtime submission check confirming an empty optional value is removed from listing metadata

Any linked issues

Checklist

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant