I am using hooks change for the first time, it is great !
{
name: 'Ajouter un nouveau contrat de maintenance',
type: 'single',
fields: [{
field: 'Recherche fournisseur',
type: 'String'
}, {
field: 'Fournisseur',
type: 'Enum',
enums: []
}],
hooks: {
change: {
['Recherche fournisseur']: ({ fields, record }) => {
if (fields['Recherche fournisseur'].value.length > 2) {
return axios.get(`${API_URL}/forest_admin/sage_providers`, {
headers: {
'Authorization': `Bearer ${process.env.ACCESS_TOKEN}`,
'X-CURRENT-USER-EMAIL': process.env.SERVICE_EMAIL
},
params: {
place_id: '',
provider_name: fields['Recherche fournisseur'].value,
siret: '',
matricule: ''
}
}).then(res => {
if (res.data && res.data.length > 0) {
fields['Fournisseur'].enums = res.data.map(provider => `${provider.matricule} - ${provider.raison_sociale}`)
}
return fields;
});
}
return fields;
}
}
}
}
As you can see, I trigger a GET whenever the user type in more than 2 letters. BUT the change event is triggered after a short time whenever a single letter is typed in, which cause the user to lose focus on the input field, which might be annoying for a slow typer.
I’ve been trying to NOT return anything, or null, or an empty object {} to prevent the form fields reloading but so far I have an error each time.
Is there any way i can set the timeout before the change event triggering or condition the trigger event in a more efficient way ? Thank you.