Repository navigation
Conversation
Fails until a required select without a default renders an empty first option. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A select with no empty option always has a value: the browser selects the first option, so `required` on a select field could never fail and every submission recorded that first option as if the visitor had chosen it. Render an empty-valued first option for a required select whose default does not match one of its options. The HTML spec treats it as the select's placeholder label option, so native and plugin validation report the field as missing until the visitor picks one, and the server already rejects an empty required value. The option shows the field's `placeholder` when set. Optional selects and selects with a default are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: 7e1ff91 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
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.
What does this PR do?
A
selectfield marked required can never fail validation.FormEmbedrenders only thefield's options, so the browser preselects the first one; the visitor can submit without
touching the field and the submission records the first option as their answer. On our recruit
form, a required "desired position" select silently recorded the first position for every
applicant who skipped it.
For a required select whose
defaultValuedoes not match one of its options,FormEmbednowrenders an empty-valued first option. The HTML spec treats that as the select's placeholder label
option, so the select reports
valueMissinguntil the visitor picks something; the plugin's clientvalidation and the server (which already rejects an empty required value) both catch it. The empty
option shows the field's
placeholderwhen one is set. Optional selects, and selects with amatching default, render exactly as before.
No existing issue. I found this while moving our site to EmDash.
Type of change
Your connection to this change
Checklist
pnpm typecheckpassespnpm lintpassespnpm testpasses (or targeted tests for my change)pnpm formathas been runAI assistance disclosure
Screenshots / test output
A required select (希望職種, placeholder 選択してください) on first load, rendered from each branch's
FormEmbed.astroand client script with the plugin's stylesheet:Submitting without choosing, on this branch
tests/form-embed-select.render.test.tsrenders four selects: required without default, requiredwith a placeholder, required with a default, optional. Before the fix the first two fail (first
option is
tokyo, not the empty option), and the last two pass as controls(
Tests 2 failed | 2 passed (4)). With the fix:Tests 4 passed (4); the forms package suitepasses (17 files, 91 tests).
Note for reviewers: the admin field editor does not expose
placeholdertoday, so the emptyoption is blank unless the form was created through the API or a seed. Exposing it, and an empty
option for optional selects, would be behaviour changes I left out of this fix.
🤖 Generated with Claude Code