sonata-project / SonataAdminBundle

The missing Symfony Admin Generator
https://docs.sonata-project.org/projects/SonataAdminBundle
MIT License
2.11k stars 1.26k forks source link

select2 not working on v4 alpha 2 #7260

Closed JustDylan23 closed 3 years ago

JustDylan23 commented 3 years ago

There is no input box for me to type in that gives autocompletion. image

The documentation says that select2 is integrated with sonata admin and that it is enabled on every select without doing anything

->add('owner', ModelType::class, [
    'property' => 'username',
])

I honestly have no clue why it isn't showing up

I have both the admin-bundle and the doctrine-orm-bunde on version 4.0.0-alpha-2 currently.

JustDylan23 commented 3 years ago

image as far as I am aware it should look something like this

VincentLanglet commented 3 years ago

Isnt the ModelAutocompleteType made for this ?

JustDylan23 commented 3 years ago

ModelAutocompleteType works by calling an endpoint, there should be a client side equivalent of this, right?

JustDylan23 commented 3 years ago

In one of our projects at work some of the model type inputs have search boxes and others dont. I am really not sure what the deciding factor is to whether you get a searchbox or not.

haivala commented 3 years ago

There is search box only if there is enough choices. I don't know how many but I have noticed this in 3.* and haven't even tested 4

franmomu commented 3 years ago

Based on https://github.com/sonata-project/SonataAdminBundle/blob/82afd8a37ef233a9b00d5751f679f9810de05a57/src/Resources/public/Admin.js#L104-L132

Looks like it shows the search box when there are more than 10 results and you can modify it with the data-sonata-select2-maximumSelectionSize attribute like https://symfony.com/doc/current/bundles/SonataAdminBundle/cookbook/recipe_select2.html#disable-select2-on-some-form-elements

JustDylan23 commented 3 years ago

It would be pretty nice to have this documented somewhere, can somebody edit the documentation?

VincentLanglet commented 3 years ago

It would be pretty nice to have this documented somewhere, can somebody edit the documentation?

You're welcome to do it ;)