From 80b0014878f5d9249107351db4378d747c44fec5 Mon Sep 17 00:00:00 2001 From: Mike Date: Tue, 14 Jan 2025 21:41:05 +0000 Subject: [PATCH] Enable multiple data types for default value in hidden widgets (#306) --- src/lib/services/contents/widgets/hidden/helper.js | 4 ++-- src/lib/typedefs.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lib/services/contents/widgets/hidden/helper.js b/src/lib/services/contents/widgets/hidden/helper.js index 1d0460f8..65f153d0 100644 --- a/src/lib/services/contents/widgets/hidden/helper.js +++ b/src/lib/services/contents/widgets/hidden/helper.js @@ -4,14 +4,14 @@ import { generateUUID } from '@sveltia/utils/crypto'; * Get the default value for a Hidden field. * @param {HiddenField} fieldConfig - Field configuration. * @param {LocaleCode} locale - Locale code. - * @returns {string} Default value. + * @returns {any} Default value. * @todo Write tests for this. */ export const getDefaultValue = (fieldConfig, locale) => { const { default: defaultValue } = fieldConfig; if (typeof defaultValue !== 'string') { - return ''; + return defaultValue; } return defaultValue.replaceAll(/{{(.+?)}}/g, (_match, tag) => { diff --git a/src/lib/typedefs.js b/src/lib/typedefs.js index d390fe82..578a1a7d 100644 --- a/src/lib/typedefs.js +++ b/src/lib/typedefs.js @@ -632,7 +632,7 @@ /** * Hidden field properties. * @typedef {object} HiddenFieldProps - * @property {string} [default] - Default value. + * @property {any} [default] - Default value. * @see https://decapcms.org/docs/widgets/#hidden */