Select2 and minimum input setting

2,173 views
Skip to first unread message

Fabrizio Pucci

unread,
Oct 20, 2013, 8:50:29 AM10/20/13
to sonata...@googlegroups.com
Hi,
I unsuccessfully tried to add the Select2 minimum input setting, in sonata admin.


I added the following code to the copy of the file "base_edit.html.twig"

{% block javascripts %}
    {{ parent() }}
    <script type="text/javascript">
        $(document).ready(function() {  
         $(".select2-choice").select2({
    minimumInputLength: 3
    });
   
});
           
    </script>
{% endblock %}


I created "edit.html.twig" file with this code

{% extends 'EstaticaSitoBundle:Admin:base_edit.html.twig' %}


In admin.yml I added:

calls:
            - [ setTemplate, [edit, MyBundle:Admin:edit.html.twig]]


By testing the result, the JavaScript code was added to the edit page, but to the dropdown has not been added the functionality "minimum input".
Any advice?

Thomas Rabaix

unread,
Oct 21, 2013, 5:15:27 AM10/21/13
to sonata...@googlegroups.com
Are you aware that the latest version include an native integration with select2 ?


--
You received this message because you are subscribed to the Google Groups "sonata-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonata-users...@googlegroups.com.
To post to this group, send email to sonata...@googlegroups.com.
Visit this group at http://groups.google.com/group/sonata-users.
For more options, visit https://groups.google.com/groups/opt_out.



--
Thomas Rabaix
http://rabaix.net | http://sonata-project.org

Fabrizio Pucci

unread,
Oct 22, 2013, 4:03:29 AM10/22/13
to sonata...@googlegroups.com, tho...@rabaix.net
Yeah, I'm just using that version!

The problem is that for very large pull-down menu, the default behavior of Select2 does not fit (the loading time is very long), you must enable the minimum input

From http://ivaynberg.github.io/select2/

"
Minimum Input
Select2 supports a minimum input setting which is useful for large remote datasets where short search terms are not very useful"

Example Code

  1. $("#e3").select2({
  2. minimumInputLength: 2
  3. });

What I'm trying to do is to add this option to the latest version of sonata admin, the one that supports select2

Thanks
Fabrizio Pucci


Il giorno lunedì 21 ottobre 2013 11:15:27 UTC+2, Thomas Rabaix ha scritto:
Are you aware that the latest version include an native integration with select2 ?

l3ia-et

unread,
Mar 25, 2014, 2:03:36 PM3/25/14
to sonata...@googlegroups.com
Hi everyone,

I've got this problem too, a table Client with 2k lines, and another table Contact with 3k lines. (and some other with 50K lines that is really the problem)

I've used select2, and the Bruno Roux's modification to add minimumInputLength (with select2_minimum_input_length into the config.yml)

The problem is that the big query is still done, so where is the benefit ?

I can see it into the DB log panel, the number of queries is the same, if I set use_select2: true ou false

I thought that data will be transfered after the minimum input length was reached (and not at the document.ready event)

was I wrong ?

is there another way to do that ?

thanks

l3ia-et

unread,
Mar 25, 2014, 2:09:40 PM3/25/14
to sonata...@googlegroups.com
ok, i havent read enough, there is this option called
ajax
Reply all
Reply to author
Forward
0 new messages