MCPcopy Index your code
hub / github.com/TanStack/form / constructor

Method constructor

packages/form-core/src/FormApi.ts:981–1330  ·  view source on GitHub ↗

* Constructs a new `FormApi` instance with the given form options.

(
    opts?: FormOptions<
      TFormData,
      TOnMount,
      TOnChange,
      TOnChangeAsync,
      TOnBlur,
      TOnBlurAsync,
      TOnSubmit,
      TOnSubmitAsync,
      TOnDynamic,
      TOnDynamicAsync,
      TOnServer,
      TSubmitMeta
    >,
  )

Source from the content-addressed store, hash-verified

979 * Constructs a new `FormApi` instance with the given form options.
980 */
981 constructor(
982 opts?: FormOptions<
983 TFormData,
984 TOnMount,
985 TOnChange,
986 TOnChangeAsync,
987 TOnBlur,
988 TOnBlurAsync,
989 TOnSubmit,
990 TOnSubmitAsync,
991 TOnDynamic,
992 TOnDynamicAsync,
993 TOnServer,
994 TSubmitMeta
995 >,
996 ) {
997 this.timeoutIds = {
998 validations: {} as Record<ValidationCause, never>,
999 listeners: {} as Record<ListenerCause, never>,
1000 formListeners: {} as Record<ListenerCause, never>,
1001 }
1002
1003 this._formId = opts?.formId ?? uuidv4()
1004
1005 this._devtoolsSubmissionOverride = false
1006
1007 this.baseStore = new Store(
1008 getDefaultFormState({
1009 ...(opts?.defaultState as any),
1010 values: opts?.defaultValues ?? opts?.defaultState?.values,
1011 isFormValid: true,
1012 }),
1013 )
1014
1015 this.fieldMetaDerived = new Derived({
1016 deps: [this.baseStore],
1017 fn: ({ prevDepVals, currDepVals, prevVal: _prevVal }) => {
1018 const prevVal = _prevVal as
1019 | Record<DeepKeys<TFormData>, AnyFieldMeta>
1020 | undefined
1021 const prevBaseStore = prevDepVals?.[0]
1022 const currBaseStore = currDepVals[0]
1023
1024 let originalMetaCount = 0
1025
1026 const fieldMeta = {} as FormState<
1027 TFormData,
1028 TOnMount,
1029 TOnChange,
1030 TOnChangeAsync,
1031 TOnBlur,
1032 TOnBlurAsync,
1033 TOnSubmit,
1034 TOnSubmitAsync,
1035 TOnDynamic,
1036 TOnDynamicAsync,
1037 TOnServer
1038 >['fieldMeta']

Callers

nothing calls this directly

Calls 7

handleSubmitMethod · 0.95
getByFunction · 0.90
isNonEmptyArrayFunction · 0.90
evaluateFunction · 0.90
getDefaultFormStateFunction · 0.85
updateMethod · 0.80

Tested by

no test coverage detected