MCPcopy
hub / github.com/final-form/final-form / createForm

Function createForm

src/FinalForm.ts:166–1438  ·  view source on GitHub ↗
(config: Config<FormValues, InitialFormValues>)

Source from the content-addressed store, hash-verified

164}
165
166function createForm<
167 FormValues = Record<string, any>,
168 InitialFormValues extends Partial<FormValues> = Partial<FormValues>
169>(config: Config<FormValues, InitialFormValues>): FormApi<FormValues, InitialFormValues> {
170 if (!config) {
171 throw new Error("No config specified");
172 }
173 let {
174 debug,
175 destroyOnUnregister,
176 keepDirtyOnReinitialize,
177 initialValues,
178 mutators,
179 onSubmit,
180 validate,
181 validateOnBlur,
182 callbackScheduler,
183 ignoreUnregister,
184 } = config;
185 if (!onSubmit) {
186 throw new Error("No onSubmit function specified");
187 }
188
189 const state: InternalState<FormValues, InitialFormValues> = {
190 subscribers: { index: 0, entries: {} },
191 fieldSubscribers: Object.create(null),
192 fields: Object.create(null),
193 formState: {
194 asyncErrors: {},
195 dirtySinceLastSubmit: false,
196 modifiedSinceLastSubmit: false,
197 errors: {},
198 initialValues: initialValues && { ...initialValues } as InitialFormValues,
199
200 pristine: true,
201 submitting: false,
202 submitFailed: false,
203 submitSucceeded: false,
204 resetWhileSubmitting: false,
205 valid: true,
206 validating: 0,
207 values: (initialValues ? { ...initialValues } : {}) as FormValues,
208 },
209 lastFormState: undefined,
210 };
211 let inBatch = 0;
212 let validationPaused = false;
213 let validationBlocked = false;
214 let preventNotificationWhileValidationPaused = false;
215 let nextAsyncValidationKey = 0;
216 let nextFieldInstanceId = 0;
217 const asyncValidationPromises: { [key: number]: Promise<any> } = {};
218 const pendingAsyncCallbacks: (() => void)[] = [];
219 let asyncCallbacksScheduled = false;
220 const clearAsyncValidationPromise = (key: number) => (result: any) => {
221 delete asyncValidationPromises[key];
222 return result;
223 };

Calls 15

getMutatorApiFunction · 0.85
runValidationFunction · 0.85
notifyFormListenersFunction · 0.85
notifyFieldListenersFunction · 0.85
getInFunction · 0.85
changeValueFunction · 0.85
calculateNextFormStateFunction · 0.85
setInFunction · 0.85
memoizeFunction · 0.85
notifyFunction · 0.85
beforeSubmitFunction · 0.85
hasSyncErrorsFunction · 0.85

Tested by 2

prepareFieldSubscribersFunction · 0.68
prepareFormSubscriberFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…