Implement ComboDepartementsSearch
This commit is contained in:
parent
2c7ee82d31
commit
4217dcd94b
3 changed files with 38 additions and 4 deletions
32
app/javascript/components/ComboDepartementsSearch.js
Normal file
32
app/javascript/components/ComboDepartementsSearch.js
Normal file
|
@ -0,0 +1,32 @@
|
|||
import React, { useCallback } from 'react';
|
||||
import { ReactQueryCacheProvider } from 'react-query';
|
||||
import matchSorter from 'match-sorter';
|
||||
|
||||
import ComboSearch from './ComboSearch';
|
||||
import { queryCache } from './shared/queryCache';
|
||||
|
||||
const extraTerms = [{ code: '99', nom: 'Etranger' }];
|
||||
|
||||
function ComboDepartementsSearch(params) {
|
||||
const transformResults = useCallback((term, results) => [
|
||||
...results,
|
||||
...matchSorter(extraTerms, term, {
|
||||
keys: ['nom', 'code']
|
||||
})
|
||||
]);
|
||||
|
||||
return (
|
||||
<ReactQueryCacheProvider queryCache={queryCache}>
|
||||
<ComboSearch
|
||||
required={params.mandatory}
|
||||
hiddenFieldId={params.hiddenFieldId}
|
||||
scope="departements"
|
||||
minimumInputLength={1}
|
||||
transformResult={({ code, nom }) => [code, `${code} - ${nom}`]}
|
||||
transformResults={transformResults}
|
||||
/>
|
||||
</ReactQueryCacheProvider>
|
||||
);
|
||||
}
|
||||
|
||||
export default ComboDepartementsSearch;
|
3
app/javascript/loaders/ComboDepartementsSearch.js
Normal file
3
app/javascript/loaders/ComboDepartementsSearch.js
Normal file
|
@ -0,0 +1,3 @@
|
|||
import Loadable from '../components/Loadable';
|
||||
|
||||
export default Loadable(() => import('../components/ComboDepartementsSearch'));
|
|
@ -1,4 +1,3 @@
|
|||
= form.select :value, [champ.value].compact,
|
||||
{ include_blank: true },
|
||||
required: champ.mandatory?,
|
||||
class: 'select2 departements'
|
||||
- hidden_field_id = SecureRandom.uuid
|
||||
= form.hidden_field :value, { data: { uuid: hidden_field_id } }
|
||||
= react_component("ComboDepartementsSearch", mandatory: champ.mandatory?, hiddenFieldId: hidden_field_id)
|
||||
|
|
Loading…
Add table
Reference in a new issue