From 613e5d6a5f4d48ad33d2d70d3178d2baf7858b7b Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Wed, 6 May 2020 23:28:36 +0530 Subject: [PATCH] feat: Allow default to be a function --- model/document.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/model/document.js b/model/document.js index 3a2d95a8..34dd3c41 100644 --- a/model/document.js +++ b/model/document.js @@ -111,7 +111,11 @@ module.exports = class BaseDocument extends Observable { defaultValue = []; } if (field.default) { - defaultValue = field.default; + if (typeof field.default === 'function') { + defaultValue = field.default(this); + } else { + defaultValue = field.default; + } } this[field.fieldname] = defaultValue;