File tree Expand file tree Collapse file tree 2 files changed +16
-3
lines changed
packages/form/src/fields/array Expand file tree Collapse file tree 2 files changed +16
-3
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ " @sjsf/form " : patch
3
+ ---
4
+
5
+ Fix population of missing tuple items
Original file line number Diff line number Diff line change @@ -56,6 +56,7 @@ export interface ArrayContext<V extends Validator> {
56
56
moveItemDown ( index : number ) : void ;
57
57
copyItem ( index : number ) : void ;
58
58
removeItem ( index : number ) : void ;
59
+ ensureArrayLength ( length : number ) : void ;
59
60
}
60
61
61
62
const ARRAY_CONTEXT = Symbol ( "array-context" ) ;
@@ -146,6 +147,15 @@ function createItemsAPI<V extends Validator>(
146
147
keyedArray . remove ( index ) ;
147
148
validate ( ) ;
148
149
} ,
150
+ ensureArrayLength ( length ) {
151
+ let l = value ( ) ?. length ;
152
+ if ( l === undefined ) {
153
+ return ;
154
+ }
155
+ for ( ; l < length ; l ++ ) {
156
+ keyedArray . push ( undefined ) ;
157
+ }
158
+ } ,
149
159
} satisfies Partial < ArrayContext < V > > ;
150
160
}
151
161
@@ -249,9 +259,7 @@ export function createTupleContext<V extends Validator>(
249
259
setValue ( new Array ( itemsSchema . length ) ) ;
250
260
return ;
251
261
}
252
- if ( val . length < itemsSchema . length ) {
253
- val . push ( ...new Array ( itemsSchema . length - value . length ) ) ;
254
- }
262
+ api . ensureArrayLength ( itemsSchema . length ) ;
255
263
} ) ;
256
264
257
265
const schemaAdditionalItems = $derived . by ( ( ) => {
You can’t perform that action at this time.
0 commit comments