From 827cad114a857ba4053a2cc21c30695a1159afd9 Mon Sep 17 00:00:00 2001 From: Faris Ansari Date: Tue, 24 Dec 2019 15:40:31 +0530 Subject: [PATCH] fix: Mandatory check --- model/document.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/model/document.js b/model/document.js index ee18de8f..a1bc6e4c 100644 --- a/model/document.js +++ b/model/document.js @@ -187,15 +187,17 @@ module.exports = class BaseDocument extends Observable { } validateMandatory() { - let missingMandatory = [getMissingMandatory(this)]; + let checkForMandatory = [this]; let tableFields = this.meta.fields.filter(df => df.fieldtype === 'Table'); tableFields.map(df => { let rows = this[df.fieldname]; - for (let row of rows) { - missingMandatory = missingMandatory.concat(getMissingMandatory(row)); - } + checkForMandatory = [...checkForMandatory, ...rows]; }); + let missingMandatory = checkForMandatory + .map(doc => getMissingMandatory(doc)) + .filter(Boolean); + if (missingMandatory.length > 0) { let fields = missingMandatory.join('\n'); let message = frappe._('Value missing for {0}', fields); @@ -217,7 +219,7 @@ module.exports = class BaseDocument extends Observable { }) .join(', '); - if (doc.meta.isChild) { + if (message && doc.meta.isChild) { let parentfield = doc.parentdoc.meta.getField(doc.parentfield); message = `${parentfield.label} Row ${doc.idx + 1}: ${message}`; }