Skip to content

Commit

Permalink
negative value for array variables when resizing (#1151)
Browse files Browse the repository at this point in the history
  • Loading branch information
renaud23 authored Sep 25, 2024
1 parent cff24a0 commit d699cb9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/stories/input-number/source.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"response": { "name": "NB" }
}
],
"resizing": { "NB": { "size": "NB", "variables": ["NAMES"] } },
"variables": [
{
"variableType": "COLLECTED",
Expand All @@ -28,6 +29,17 @@
"EDITED": null,
"INPUTED": null
}
},
{
"variableType": "COLLECTED",
"name": "NAMES",
"values": {
"PREVIOUS": null,
"COLLECTED": [null],
"FORCED": null,
"EDITED": null,
"INPUTED": null
}
}
]
}
6 changes: 5 additions & 1 deletion src/use-lunatic/reducer/commons/resize-array-variable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@ function resizeArrayVariable<T = unknown>(
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)
Expand Down

0 comments on commit d699cb9

Please sign in to comment.