mirror of
https://github.com/frappe/books.git
synced 2025-01-12 19:06:38 +00:00
feat: add convenience function to get fields meta map
This commit is contained in:
parent
317eb3116b
commit
0af2ce86f4
@ -194,7 +194,6 @@ module.exports = class BaseDocument extends Observable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
validateMandatory() {
|
validateMandatory() {
|
||||||
const fieldValueMap = this.getFieldValueMap();
|
|
||||||
let checkForMandatory = [this];
|
let checkForMandatory = [this];
|
||||||
let tableFields = this.meta.fields.filter((df) => df.fieldtype === 'Table');
|
let tableFields = this.meta.fields.filter((df) => df.fieldtype === 'Table');
|
||||||
tableFields.map((df) => {
|
tableFields.map((df) => {
|
||||||
@ -215,7 +214,7 @@ module.exports = class BaseDocument extends Observable {
|
|||||||
function getMissingMandatory(doc) {
|
function getMissingMandatory(doc) {
|
||||||
let mandatoryFields = doc.meta.fields.filter((df) => {
|
let mandatoryFields = doc.meta.fields.filter((df) => {
|
||||||
if (df.required instanceof Function) {
|
if (df.required instanceof Function) {
|
||||||
return df.required(fieldValueMap);
|
return df.required(doc);
|
||||||
}
|
}
|
||||||
return df.required;
|
return df.required;
|
||||||
});
|
});
|
||||||
@ -702,4 +701,11 @@ module.exports = class BaseDocument extends Observable {
|
|||||||
}, {});
|
}, {});
|
||||||
return Object.freeze(fieldValueMap);
|
return Object.freeze(fieldValueMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getFieldMetaMap() {
|
||||||
|
return this.meta.fields.reduce((obj, meta) => {
|
||||||
|
obj[meta.fieldname] = meta;
|
||||||
|
return obj;
|
||||||
|
}, {});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user