Repository navigation
[6.x] Keep blank Dropdown option values - #20140
Merged
Merged
Conversation
A blank option value is posted as null (ConvertEmptyStringsToNull) and dropped on save, so the option lost its "value" key and creating an entry failed with "Undefined array key". Options now default label and value to an empty string. Dropdown also encodes a blank value as __blank__, so the Choice control didn't see the field's own blank option and prepended another one. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
📚 Storybook previews@craftcms/ui — open Storybook No changed components detected in this Storybook. resources/js — open Storybook No changed components detected in this Storybook. |
riasvdv
approved these changes
Oct 29, 2026
Amp-Thread-ID: https://ampcode.com/threads/T-01a18697-77ce-73ef-a319-bc991cf9c06f Co-authored-by: Amp <amp@ampcode.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Initial issue: if you created a dropdown field with an empty value (e.g., Please select), added that field to an entry type, and tried to create an entry of that type, an exception was thrown:
Claude's explanation:
A Dropdown option with a blank value lost its
valuekey on save, so creating an entry failed withUndefined array key "value". Once that was fixed, the entry form showed a second, unlabeled blank option above the field's own blank option.Normalizing in the constructor also repairs fields that were already saved without a
valuekey when they're loaded, so no migration is needed.Evidence
tests/Feature/Field/OptionsFieldEmptyValueTest.php🤖 Generated with Claude Code