8000 [Autocomplete] Only add the clear button to a select that has an empty option by Kocal · Pull Request #4203 · symfony/ux · GitHub
[go: up one dir, main page]

Skip to content

[Autocomplete] Only add the clear button to a select that has an empty option - #4203

Merged
Kocal merged 1 commit into
symfony:3.xfrom
Kocal:autocomplete/clear-button-placeholder
Nov 3, 2026
Merged

Kocal merged 1 commit into
symfony:3.xfrom
Kocal:autocomplete/clear-button-placeholder

Conversation

@Kocal
@Kocal Kocal commented Nov 3, 2026
Copy link
Copy Markdown
Member
Q A
Bug fix? yes
New feature? no
Deprecations? no
Documentation? no
Issues Fix #402
License MIT

The Autocomplete controller adds Tom Select's clear button to every enabled single select. A required ChoiceType without a placeholder has no empty option, and Symfony also removes the required attribute from its <select>. So the user can clear the field and submit an empty value, which a native <select> does not allow.

The controller now adds the clear button only when the <select> has an option with an empty value, i.e. a placeholder. You can still enable or disable clear_button explicitly with the plugins key of tom_select_options.

This follows the approach of the earlier pull request #2282 by Ruud Seberechts (@Qronicle), which was never merged.

Field Before After
Required, no placeholder Clear button No clear button
Required, with placeholder Clear button Clear button
Not required Clear button Clear button

@Kocal Kocal self-assigned this Nov 3, 2026
@carsonbot carsonbot added Autocomplete Bug Bug Fix Status: Needs Review Needs to be reviewed labels Nov 3, 2026
@github-actions
github-actions Bot commented Nov 3, 2026
Copy link
Copy Markdown
Contributor

📊 Packages dist files size difference

Thanks for the PR! Here is the difference in size of the packages dist files between the base branch and the PR.
Please review the changes and make sure they are expected.

FileBefore (Size / Gzip)After (Size / Gzip)
Autocomplete
controller.js 12.5 kB / 3.38 kB 12.63 kB+1% 📈 / 3.41 kB+1% 📈

…y option

| Q              | A
| -------------- | ---
| Bug fix?       | yes
| New feature?   | no
| Deprecations?  | no
| Documentation? | no
| Issues         | Fix symfony#402
| License        | MIT

The Autocomplete controller adds Tom Select's clear button to every enabled single select. A required `ChoiceType` without a placeholder has no empty option, and Symfony also removes the `required` attribute from its `<select>`. So the user can clear the field and submit an empty value, which a native `<select>` does not allow.

The controller now adds the clear button only when the `<select>` has an option with an empty value, i.e. a placeholder. You can still enable or disable `clear_button` explicitly with the `plugins` key of `tom_select_options`.

This follows the approach of the earlier pull request symfony#2282 by Ruud Seberechts (@Qronicle), which was never merged.

| Field | Before | After |
| --- | --- | --- |
| Required, no plac
8000
eholder | Clear button | No clear button |
| Required, with placeholder | Clear button | Clear button |
| Not required | Clear button | Clear button |
@Kocal
Kocal force-pushed the autocomplete/clear-button-placeholder branch from 1745213 to 833d27f Compare November 3, 2026 17:28
@Kocal
Kocal commented Nov 3, 2026
Copy link
Copy Markdown
Member Author

Thank you @Qronicle.

@Kocal
Kocal merged commit 69537a6 into symfony:3.x Nov 3, 2026
37 checks passed
@Kocal
Kocal deleted the autocomplete/clear-button-placeholder branch November 3, 2026 17:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Autocomplete] required choice types end up not being required.

3 participants

0