MCPcopy Create free account
hub / github.com/RtlZeroMemory/Rezi / append

Function append

packages/core/src/forms/internal/arrayState.ts:164–227  ·  view source on GitHub ↗
(item: ArrayFieldItem<T, K>)

Source from the content-addressed store, hash-verified

162 );
163
164 const append = (item: ArrayFieldItem<T, K>): void => {
165 options.pendingAsyncValuesRef.current = null;
166
167 options.updateFormState((prev) => {
168 if (prev.isSubmitting || !options.isFieldEditableInternal(fieldKey, prev)) {
169 return prev;
170 }
171
172 const currentValues = getArrayFieldValues(prev.values, field);
173 const nextValuesArray = [...currentValues, item];
174 const nextValues = {
175 ...prev.values,
176 [field]: nextValuesArray as unknown as T[K],
177 };
178 options.pendingAsyncValuesRef.current = nextValues;
179
180 const nextTouched = [
181 ...normalizeBooleanArray(prev.touched[fieldKey], currentValues.length, false),
182 false,
183 ];
184 const nextDirty = computeFieldDirty(
185 fieldKey,
186 nextValuesArray as T[keyof T],
187 options.initialValuesRef.current,
188 );
189
190 let nextErrors = prev.errors;
191 if (options.validateOnChange) {
192 nextErrors = options.runSyncValidationFiltered(nextValues, prev);
193 } else {
194 nextErrors = {
195 ...prev.errors,
196 [fieldKey]: remapFieldArrayErrors(
197 prev.errors[fieldKey],
198 currentValues.length,
199 (errs) => [...errs, undefined],
200 ),
201 };
202 }
203
204 appendFieldArrayKey(fieldKey, options.fieldArrayKeysRef, options.fieldArrayKeyCounterRef);
205
206 return {
207 ...prev,
208 values: nextValues,
209 errors: nextErrors,
210 submitError: undefined,
211 touched: {
212 ...prev.touched,
213 [fieldKey]: nextTouched,
214 },
215 dirty: {
216 ...prev.dirty,
217 [fieldKey]: nextDirty,
218 },
219 };
220 });
221

Callers

nothing calls this directly

Calls 6

getArrayFieldValuesFunction · 0.85
normalizeBooleanArrayFunction · 0.85
computeFieldDirtyFunction · 0.85
remapFieldArrayErrorsFunction · 0.85
appendFieldArrayKeyFunction · 0.85
runMethod · 0.65

Tested by

no test coverage detected