Skip to content

Add pleaseChoose option to SelectElement#200

Merged
lippserd merged 1 commit into
mainfrom
feature/default-please-choose-option
Jun 24, 2026
Merged

Add pleaseChoose option to SelectElement#200
lippserd merged 1 commit into
mainfrom
feature/default-please-choose-option

Conversation

@jrauh01

@jrauh01 jrauh01 commented May 27, 2026

Copy link
Copy Markdown
Contributor

Add a pleaseChoose option to SelectElement that prepends the placeholder automatically:

(new SelectElement('type'))
    ->setOptions($types)
    ->setPleaseChoose(true);

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

@jrauh01 jrauh01 self-assigned this May 27, 2026
@cla-bot cla-bot Bot added the cla/signed label May 27, 2026
@jrauh01 jrauh01 requested a review from Copilot May 27, 2026 08:53

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 pleaseChoose property with setPleaseChoose() setter.
  • assemble() prepends a disabled SelectOption with empty value when pleaseChoose is enabled and no top-level '' option already exists; selection callback reuses isSelectedOption('').
  • Registers a pleaseChoose declarative 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.

@jrauh01 jrauh01 requested a review from lippserd May 29, 2026 10:43
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.
@jrauh01 jrauh01 force-pushed the feature/default-please-choose-option branch from cef48ce to 4d3a51e Compare June 22, 2026 08:10
@lippserd lippserd added this to the v0.11.0 milestone Jun 24, 2026
@lippserd lippserd merged commit 2835c3a into main Jun 24, 2026
13 checks passed
@lippserd lippserd deleted the feature/default-please-choose-option branch June 24, 2026 16:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Let SelectElement support a built-in default "Please choose" option

3 participants