Merge pull request #4699 from tchak/search-by-code
Search departements by code
This commit is contained in:
commit
35aceeb5e6
2 changed files with 17 additions and 1 deletions
|
@ -1,5 +1,6 @@
|
|||
import $ from 'jquery';
|
||||
import 'select2';
|
||||
import { isNumeric } from '@utils';
|
||||
|
||||
const { api_geo_url, api_adresse_url } = gon.autocomplete || {};
|
||||
|
||||
|
@ -80,10 +81,21 @@ const communesOptions = {
|
|||
const etranger99 = { id: '99 - Étranger', text: '99 - Étranger' };
|
||||
const departementsOptions = {
|
||||
...baseOptions,
|
||||
minimumInputLength: 2,
|
||||
minimumInputLength: 1,
|
||||
ajax: {
|
||||
...baseAjaxOptions,
|
||||
url: `${api_geo_url}/departements`,
|
||||
data({ term }) {
|
||||
const data = { fields: 'nom,code' };
|
||||
|
||||
if (isNumeric(term)) {
|
||||
data.code = term.trim().padStart(2, '0');
|
||||
} else {
|
||||
data.nom = term;
|
||||
}
|
||||
|
||||
return data;
|
||||
},
|
||||
processResults(data) {
|
||||
return {
|
||||
results: data
|
||||
|
|
|
@ -78,6 +78,10 @@ export function to(promise) {
|
|||
return promise.then(result => [result]).catch(error => [null, error]);
|
||||
}
|
||||
|
||||
export function isNumeric(n) {
|
||||
return !isNaN(parseFloat(n)) && isFinite(n);
|
||||
}
|
||||
|
||||
function offset(element) {
|
||||
const rect = element.getBoundingClientRect();
|
||||
return {
|
||||
|
|
Loading…
Reference in a new issue