diff --git a/app/javascript/components/shared/queryClient.ts b/app/javascript/components/shared/queryClient.ts index d24056928..e356263c1 100644 --- a/app/javascript/components/shared/queryClient.ts +++ b/app/javascript/components/shared/queryClient.ts @@ -26,7 +26,7 @@ type QueryKey = readonly [ ]; function buildURL(scope: string, term: string, extra?: string) { - term = encodeURIComponent(term.replace(/\(|\)/g, '')); + term = term.replace(/\(|\)/g, ''); const params = new URLSearchParams(); let path = `${api_geo_url}/${scope}`; @@ -73,6 +73,11 @@ const defaultQueryFn: QueryFunction = async ({ return matchSorter(await getPays(signal), term, { keys: ['label'] }); } + // BAN will error with queries less then 3 chars long + if (scope == 'adresse' && term.length < 3) { + return []; + } + const url = buildURL(scope, term, extra); return httpRequest(url, { csrf: false, signal }).json(); };