diff --git a/client/src/components/CustomerOrderForm.tsx b/client/src/components/CustomerOrderForm.tsx index 338e818..9ed56e6 100644 --- a/client/src/components/CustomerOrderForm.tsx +++ b/client/src/components/CustomerOrderForm.tsx @@ -159,6 +159,8 @@ export function CustomerOrderForm({ // Lookup API ffnancy par gencode ou référence const [articleLookupLoading, setArticleLookupLoading] = useState(false); const [articleNotFound, setArticleNotFound] = useState(false); + // Flag pour éviter que le remplissage auto de productReference ne redéclenche une recherche + const autoFilledRef = useRef(false); const lookupDebounceRef = useRef | null>(null); const gencodeValue = form.watch("gencode"); const referenceValue = form.watch("productReference"); @@ -174,6 +176,7 @@ export function CustomerOrderForm({ if (!article) { setArticleNotFound(true); return; } setArticleNotFound(false); + autoFilledRef.current = true; // bloquer le watcher référence form.setValue("productName", article.libelle1, { shouldValidate: true }); if (article.gtin) form.setValue("gencode", article.gtin, { shouldValidate: true }); if (article.ref_fou_principale) form.setValue("productReference", article.ref_fou_principale, { shouldValidate: true }); @@ -216,6 +219,8 @@ export function CustomerOrderForm({ }, [gencodeValue]); useEffect(() => { + // Si la valeur a été remplie automatiquement, on ignore ce cycle + if (autoFilledRef.current) { autoFilledRef.current = false; return; } if (!referenceValue || referenceValue.length < 3) { setArticleNotFound(false); return; } if (lookupDebounceRef.current) clearTimeout(lookupDebounceRef.current); lookupDebounceRef.current = setTimeout(() => { diff --git a/client/src/pages/mobile/CustomerOrdersPage.tsx b/client/src/pages/mobile/CustomerOrdersPage.tsx index 39ffcc3..8981be4 100644 --- a/client/src/pages/mobile/CustomerOrdersPage.tsx +++ b/client/src/pages/mobile/CustomerOrdersPage.tsx @@ -186,6 +186,7 @@ export default function MobileCustomerOrdersPage() { // Lookup API ffnancy par gencode ou référence const [articleLookupLoading, setArticleLookupLoading] = useState(false); const [articleNotFound, setArticleNotFound] = useState(false); + const autoFilledRef = useRef(false); const lookupDebounceRef = useRef | null>(null); const gencodeValue = form.watch("gencode"); const referenceValue = form.watch("productReference"); @@ -201,6 +202,7 @@ export default function MobileCustomerOrdersPage() { if (!article) { setArticleNotFound(true); return; } setArticleNotFound(false); + autoFilledRef.current = true; form.setValue("productName", article.libelle1, { shouldValidate: true }); if (article.gtin) form.setValue("gencode", article.gtin, { shouldValidate: true }); if (article.ref_fou_principale) form.setValue("productReference", article.ref_fou_principale, { shouldValidate: true }); @@ -242,6 +244,7 @@ export default function MobileCustomerOrdersPage() { }, [gencodeValue]); useEffect(() => { + if (autoFilledRef.current) { autoFilledRef.current = false; return; } if (!referenceValue || referenceValue.length < 3) { setArticleNotFound(false); return; } if (lookupDebounceRef.current) clearTimeout(lookupDebounceRef.current); lookupDebounceRef.current = setTimeout(() => {