Skip to content

Commit

Permalink
bug #5991 Fix the creation of autocomplete widgets (javiereguiluz)
Browse files Browse the repository at this point in the history
This PR was squashed before being merged into the 4.x branch.

Discussion
----------

Fix the creation of autocomplete widgets

Fixes #5981.

I had to revert the changes made by `@ksn135` in #5705. Sorry!

I tried to minimize the issues by solving the problem with the `ChoiceFilter` mentioned in the original PR.

Commits
-------

136b6c3 Fix the creation of autocomplete widgets
  • Loading branch information
javiereguiluz committed Oct 31, 2023
2 parents 7b7c881 + 136b6c3 commit bf76d49
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 8 deletions.
4 changes: 0 additions & 4 deletions assets/js/autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ export default class Autocomplete
return this.#createAutocompleteWithHtmlContents(element);
}

// needed because choice fields can be displayed as a expanded list of
// values without autocompletion. See https://github.com/EasyCorp/EasyAdminBundle/pull/5705
if (! element.hasAttribute('value')) return;

return this.#createAutocomplete(element);
}

Expand Down
6 changes: 6 additions & 0 deletions src/Form/Filter/Type/ChoiceFilterType.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
{
$multiple = (bool) $builder->get('value')->getOption('multiple');

// if the filter shows the values as checkboxes or radio buttons, remove the
// attribute that turns the <select> into an autocomplete widget
if (true === ($options['value_type_options']['expanded'] ?? false)) {
unset($options['value_type_options']['attr']['data-ea-widget']);
}

$builder->addModelTransformer(new CallbackTransformer(
static fn ($data) => $data,
static function ($data) use ($multiple) {
Expand Down

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/Resources/public/entrypoints.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"/app.052a1081.rtl.css"
],
"js": [
"/app.e7951020.js"
"/app.1357e916.js"
]
},
"form": {
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/public/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"app.css": "app.052a1081.css",
"app.rtl.css": "app.052a1081.rtl.css",
"app.js": "app.e7951020.js",
"app.js": "app.1357e916.js",
"form.js": "form.fc39362b.js",
"page-layout.js": "page-layout.3347892e.js",
"page-color-scheme.js": "page-color-scheme.a1970567.js",
Expand Down

0 comments on commit bf76d49

Please sign in to comment.