diff --git a/src/stories/input-number/source.json b/src/stories/input-number/source.json index 34dbadfa4..96da7b3e3 100644 --- a/src/stories/input-number/source.json +++ b/src/stories/input-number/source.json @@ -17,6 +17,7 @@ "response": { "name": "NB" } } ], + "resizing": { "NB": { "size": "NB", "variables": ["NAMES"] } }, "variables": [ { "variableType": "COLLECTED", @@ -28,6 +29,17 @@ "EDITED": null, "INPUTED": null } + }, + { + "variableType": "COLLECTED", + "name": "NAMES", + "values": { + "PREVIOUS": null, + "COLLECTED": [null], + "FORCED": null, + "EDITED": null, + "INPUTED": null + } } ] } diff --git a/src/use-lunatic/reducer/commons/resize-array-variable.ts b/src/use-lunatic/reducer/commons/resize-array-variable.ts index 975c20c90..57197f2c6 100644 --- a/src/use-lunatic/reducer/commons/resize-array-variable.ts +++ b/src/use-lunatic/reducer/commons/resize-array-variable.ts @@ -6,10 +6,14 @@ function resizeArrayVariable( length: number, defaultValue?: T ): T[] { + if (length < 0) { + return []; + } if (!Array.isArray(array)) { // create the array return new Array(length).fill(defaultValue); - } else if (array.length !== length) { + } + if (array.length !== length) { // renew array end keep previous values return new Array(length) .fill(defaultValue)