From 4144a3cd4362e4a878222f127a9ef384a5f35448 Mon Sep 17 00:00:00 2001 From: Stefano Ricci <1219739+SteRiccio@users.noreply.github.com> Date: Fri, 24 Jan 2025 12:07:00 +0100 Subject: [PATCH] Validations min/max count: allow zeros (backward compatibility) (#3714) Co-authored-by: Stefano Ricci --- core/survey/_surveyValidator/nodeDefValidationsValidator.js | 2 +- webapp/components/survey/NodeDefDetails/ValidationsProps.js | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/core/survey/_surveyValidator/nodeDefValidationsValidator.js b/core/survey/_surveyValidator/nodeDefValidationsValidator.js index 650e905b03..71f81e729d 100644 --- a/core/survey/_surveyValidator/nodeDefValidationsValidator.js +++ b/core/survey/_surveyValidator/nodeDefValidationsValidator.js @@ -16,7 +16,7 @@ const validateCountProp = const count = Validator.getProp(propName)(item) return Array.isArray(count) ? NodeDefExpressionsValidator.validate(survey, nodeDef, dependencyType) - : Validator.validatePositiveNumber(errorKey)(propName, item) + : Validator.validatePositiveOrZeroNumber(errorKey)(propName, item) } export const validate = async (survey, nodeDef) => { diff --git a/webapp/components/survey/NodeDefDetails/ValidationsProps.js b/webapp/components/survey/NodeDefDetails/ValidationsProps.js index 3e43aa5680..9131a6afe0 100644 --- a/webapp/components/survey/NodeDefDetails/ValidationsProps.js +++ b/webapp/components/survey/NodeDefDetails/ValidationsProps.js @@ -22,6 +22,8 @@ import { State } from './store' const countTypes = [NodeDefValidations.keys.min, NodeDefValidations.keys.max] +const countPropNumberFormat = NumberFormats.integer({ allowNegative: false }) + const CountProp = (props) => { const { Actions, countType, nodeDef, nodeDefUuidContext, readOnly, state } = props @@ -65,7 +67,7 @@ const CountProp = (props) => { excludeCurrentNodeDef valueTypeSelection determineValueType={determineValueType} - valueConstantEditorNumberFormat={NumberFormats.integer()} + valueConstantEditorNumberFormat={countPropNumberFormat} /> )