From b6d6e36574d51f34346a044f736c5346342afbde Mon Sep 17 00:00:00 2001 From: elforjani3 Date: Wed, 28 Oct 2020 17:40:30 +0200 Subject: [PATCH] Fix Entries validation --- client/src/containers/Sales/Estimate/EstimateForm.js | 8 +++++++- client/src/containers/Sales/Invoice/InvoiceForm.js | 7 ++++++- client/src/containers/Sales/Receipt/ReceiptForm.js | 7 ++++++- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/client/src/containers/Sales/Estimate/EstimateForm.js b/client/src/containers/Sales/Estimate/EstimateForm.js index 97ead1a26..6a172266f 100644 --- a/client/src/containers/Sales/Estimate/EstimateForm.js +++ b/client/src/containers/Sales/Estimate/EstimateForm.js @@ -116,7 +116,13 @@ const EstimateForm = ({ .label(formatMessage({ id: 'note' })), entries: Yup.array().of( Yup.object().shape({ - quantity: Yup.number().nullable(), + quantity: Yup.number() + .nullable() + .when(['rate'], { + is: (rate) => rate, + then: Yup.number().required(), + }), + rate: Yup.number().nullable(), item_id: Yup.number() .nullable() .when(['quantity', 'rate'], { diff --git a/client/src/containers/Sales/Invoice/InvoiceForm.js b/client/src/containers/Sales/Invoice/InvoiceForm.js index b7f425157..761c7cf38 100644 --- a/client/src/containers/Sales/Invoice/InvoiceForm.js +++ b/client/src/containers/Sales/Invoice/InvoiceForm.js @@ -115,7 +115,12 @@ function InvoiceForm({ entries: Yup.array().of( Yup.object().shape({ - quantity: Yup.number().nullable(), + quantity: Yup.number() + .nullable() + .when(['rate'], { + is: (rate) => rate, + then: Yup.number().required(), + }), rate: Yup.number().nullable(), item_id: Yup.number() .nullable() diff --git a/client/src/containers/Sales/Receipt/ReceiptForm.js b/client/src/containers/Sales/Receipt/ReceiptForm.js index 14b4b0320..129491b96 100644 --- a/client/src/containers/Sales/Receipt/ReceiptForm.js +++ b/client/src/containers/Sales/Receipt/ReceiptForm.js @@ -116,7 +116,12 @@ function ReceiptForm({ entries: Yup.array().of( Yup.object().shape({ - quantity: Yup.number().nullable(), + quantity: Yup.number() + .nullable() + .when(['rate'], { + is: (rate) => rate, + then: Yup.number().required(), + }), rate: Yup.number().nullable(), item_id: Yup.number() .nullable()