Add pleaseChoose option to SelectElement#200
Open
jrauh01 wants to merge 1 commit into
Open
Conversation
When set, a disabled " - Please choose - " option with an empty value is prepended automatically, so callers no longer need to merge it into the options array and separately add '' to `disabledOptions`. The option is skipped when the options array already contains a '' key, so existing callers that manage their own placeholder are unaffected.
There was a problem hiding this comment.
Pull request overview
Adds a pleaseChoose option to SelectElement that lazily prepends a disabled '' placeholder option (" - Please choose - ") at assembly time, both via a fluent setter and a declarative attribute. The change centralizes a repeated pattern previously duplicated across forms (issue #199).
Changes:
- New
pleaseChooseproperty withsetPleaseChoose()setter. assemble()prepends a disabledSelectOptionwith empty value whenpleaseChooseis enabled and no top-level''option already exists; selection callback reusesisSelectedOption('').- Registers a
pleaseChoosedeclarative attribute setter callback (matching the first-class-callable style already used elsewhere) and adds four tests covering rendering, value-selection, non-override, and lazy fluent API behavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/FormElement/SelectElement.php | Adds $pleaseChoose flag, setter, assembly-time placeholder injection, and declarative attribute callback. |
| tests/FormElement/SelectElementTest.php | Adds four tests covering prepend rendering, deselection when a value is set, no-override of existing empty option, and lazy fluent-API behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Add a
pleaseChooseoption toSelectElementthat prepends the placeholder automatically:Or declaratively:
[ 'type' => 'select', 'options' => $types, 'pleaseChoose' => true, ]When enabled and no
''option does exist, the element prepends['' => sprintf(' - %s - ', t('Please choose'))]to the rendered options and marks it as disabled, so callers do not need to handle either step.resolve #199