From f60c181ba86f86b5f20c40835499ac239b2102bc Mon Sep 17 00:00:00 2001 From: Ole Martin Handeland Date: Tue, 26 Nov 2024 14:14:34 +0100 Subject: [PATCH] Allowing `maxCount: 1` in RepeatingGroup (#2757) Co-authored-by: Ole Martin Handeland --- .../devtools/utils/layoutSchemaValidation.ts | 20 +++++++++++++++++++ src/layout/RepeatingGroup/config.ts | 5 +++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/features/devtools/utils/layoutSchemaValidation.ts b/src/features/devtools/utils/layoutSchemaValidation.ts index f8989c6355..c96ee4ec01 100644 --- a/src/features/devtools/utils/layoutSchemaValidation.ts +++ b/src/features/devtools/utils/layoutSchemaValidation.ts @@ -91,6 +91,26 @@ export function formatLayoutSchemaValidationError(error: DefinedError): string | return `Ugyldig verdi for egenskapen ${propertyString}, verdien \`${error.data}\` er ikke av typen \`${ error.params.type }\` ${canBeExpression ? 'eller et uttrykk' : ''}`; + case 'minimum': + if (error.params.comparison === '>=') { + return `Ugyldig verdi for egenskapen ${propertyString}, verdien \`${error.data}\` er mindre enn minimumsverdien ${ + error.params.limit + }`; + } + + return `Ugyldig verdi for egenskapen ${propertyString}, verdien \`${error.data}\` er mindre enn eller lik minimumsverdien ${ + error.params.limit + }`; + case 'maximum': + if (error.params.comparison === '<=') { + return `Ugyldig verdi for egenskapen ${propertyString}, verdien \`${error.data}\` er større enn maksimumsverdien ${ + error.params.limit + }`; + } + + return `Ugyldig verdi for egenskapen ${propertyString}, verdien \`${error.data}\` er større enn eller lik maksimumsverdien ${ + error.params.limit + }`; case 'if': case 'anyOf': case 'oneOf': diff --git a/src/layout/RepeatingGroup/config.ts b/src/layout/RepeatingGroup/config.ts index a2ad34c43c..eab3b7e9d3 100644 --- a/src/layout/RepeatingGroup/config.ts +++ b/src/layout/RepeatingGroup/config.ts @@ -256,7 +256,7 @@ export const Config = new CG.component({ 'maxCount', new CG.int() .optional() - .setMin(2) + .setMin(1) .setTitle('Max number of rows') .setDescription('Maximum number of rows that can be added.'), ), @@ -265,7 +265,8 @@ export const Config = new CG.component({ new CG.prop( 'minCount', new CG.int() - .optional() + .setMin(0) + .optional({ default: 0 }) .setTitle('Min number of rows') .setDescription( 'Minimum number of rows that should be added. If the user has not added enough rows, ' +