PUGX / PUGXAutoCompleterBundle

Add an autocomplete field to your Symfony forms
GNU Lesser General Public License v3.0
93 stars 38 forks source link

Error "Cannot read properties of undefined (reading 'toUpperCase')" when using select2 version 3.5.2-browserify #76

Closed Mis0u closed 2 years ago

Mis0u commented 2 years ago

I've got this error only with select2. If I use jquery-ui it work but I want to implement select2.

My JS file :

import $ from 'jquery';
import 'select2/select2';
import '@pugx/autocompleter-bundle/js/autocompleter-select2';

$('#postal_code_search_zipcode').autocompleter({
    url_list: '/postalCode_search',
    url_get: '/postalCode_get/',
    // min_length: 3,
    otherOptions: {
        minimumInputLength: 3,
        formatNoMatches: 'Pas trouvé',
        formatSearching: 'Je cherche',
        formatInputTooShort: 'Insérer au minimum les 3 premiers chiffre'
    }
})

My Controller :

{
    #[Route('/postalCode_search', name: "postalCode_search", defaults:["_format" => "json"])]
    public function searchPostalCode(Request $request, CityRepository $cityRepository): Response
    {
        $query = $request->query->get('q');
        $results = $cityRepository->findLikePostalCode($query);

        return $this->render('json/postal_code.json.twig', ['postalCodes' => $results]);
    }

    #[Route('/postalCode_get', name: "postalCode_get")]
    public function getPostalCode(string $id, CityRepository $cityRepository): Response
    {
        $postalCode = $cityRepository->find($id);

        if (null !== $postalCode){
            $result = $postalCode->getZipcode().' '.$postalCode->getName();
        }else{
            $result = 'Aucun résultat';
        }

        return $this->json($result);
    }
}

My json twig :


[{% for postalCode in postalCodes -%}
    {{ {id: postalCode.id, label: postalCode.zipcode ~ ' ' ~ postalCode.name, value: postalCode.zipcode ~ ' ' ~ postalCode.name}|json_encode|raw }}
    {%- if not loop.last %},
    {% endif -%}
 {%- endfor %}
]

Any idea ?

garak commented 2 years ago

Can you try with lastest Select2 version? It's 3.5.7

Mis0u commented 2 years ago

I've remove last select2 and replace by the one you gave me but still the same error. In my app.js I replace the old select2 by => import 'Select2/select2.css' In my js file =>. import 'Select2/select2'

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions.

stale[bot] commented 2 years ago

This issue is closed because was marked as stale and had no activity. Thank you for your contributions.