Options
All
  • Public
  • Public/Protected
  • All
Menu

felte

Index

Type aliases

CreateSubmitHandlerConfig

CreateSubmitHandlerConfig<Data>: { onError?: FormConfig<Data>["onError"]; onSubmit?: FormConfig<Data>["onSubmit"]; validate?: FormConfig<Data>["validate"] }

Type parameters

Type declaration

CurrentForm

CurrentForm<Data>: { config: FormConfig<Data>; controls?: FormControl[]; data: Writable<Data>; errors: Writable<Errors<Data>>; form?: HTMLFormElement; touched: Writable<Touched<Data>> }

Type parameters

Type declaration

  • config: FormConfig<Data>
  • Optional controls?: FormControl[]
  • data: Writable<Data>
  • errors: Writable<Errors<Data>>
  • Optional form?: HTMLFormElement
  • touched: Writable<Touched<Data>>

DeepSetResult

DeepSetResult<Data, Value>: {[ key in keyof Data]: Data[key] extends Obj ? DeepSetResult<Data[key], Value> : Value }

Type parameters

  • Data: Obj

  • Value

Errors

Errors<Data>: {[ key in keyof Data]: Data[key] extends Obj ? Errors<Data[key]> : string | string[] | null }

The errors object may contain either a string or array or string per key.

Type parameters

Extender

Extender<Data>: (currentForm: CurrentForm<Data>) => ExtenderHandler<Data>

Type parameters

Type declaration

ExtenderHandler

ExtenderHandler<Data>: { destroy?: () => void; onSubmitError?: (state: OnSubmitErrorState<Data>) => void }

Type parameters

Type declaration

FieldValue

FieldValue: string | string[] | boolean | number | File | File[] | undefined

Possible field values.

Form

Form<Data>: { createSubmitHandler: (altConfig?: CreateSubmitHandlerConfig<Data>) => (e?: Event) => void; form: FormAction; handleSubmit: (e?: Event) => void; reset: () => void; setError: (path: string, error: string | string[]) => void; setField: (path: string, value?: FieldValue, touch?: boolean) => void; setFields: (values: Data) => void; setTouched: (path: string) => void; validate: () => Promise<Errors<Data> | void> } & Stores<Data>

The return type for the createForm function.

Type parameters

FormAction

FormAction: (node: HTMLFormElement) => { destroy: () => void }

Type declaration

    • (node: HTMLFormElement): { destroy: () => void }
    • Parameters

      • node: HTMLFormElement

      Returns { destroy: () => void }

      • destroy: () => void
          • (): void
          • Returns void

FormControl

FormControl: HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement

Obj

Obj: Record<string, unknown>

Record<string, unknown>

OnSubmitErrorState

OnSubmitErrorState<Data>: { data: Data; errors: Errors<Data> }

Type parameters

Type declaration

  • data: Data
  • errors: Errors<Data>

Reporter

Reporter<Data>: (currentForm: CurrentForm<Data>) => ReporterHandler<Data>

Type parameters

Type declaration

ReporterHandler

ReporterHandler<Data>: { destroy?: () => void; onSubmitError?: (state: OnSubmitErrorState<Data>) => void }

Type parameters

Type declaration

Stores

Stores<Data>: { data: Writable<Data>; errors: Writable<Errors<Data>>; isSubmitting: Writable<boolean>; isValid: Readable<boolean>; touched: Writable<Touched<Data>> }

The stores that createForm creates.

Type parameters

Type declaration

  • data: Writable<Data>

    Writable store that contains the form's data.

  • errors: Writable<Errors<Data>>

    Writable store that contains the form's validation errors.

  • isSubmitting: Writable<boolean>

    Writable store containing only a boolean that represents if the form is submitting.

  • isValid: Readable<boolean>

    Readable store containing only a boolean that represents if the form is valid.

  • touched: Writable<Touched<Data>>

    Writable store that denotes if any field has been touched.

Touched

Touched<Data>: {[ key in keyof Data]: Data[key] extends Obj ? Touched<Data[key]> : boolean }

The touched object may only contain booleans per key.

Type parameters

ValidationFunction

ValidationFunction<Data>: (values: Data) => Errors<Data> | undefined | Promise<Errors<Data> | undefined>

Type parameters

Type declaration

    • (values: Data): Errors<Data> | undefined | Promise<Errors<Data> | undefined>
    • Parameters

      • values: Data

      Returns Errors<Data> | undefined | Promise<Errors<Data> | undefined>

Main Functions

createForm

  • Creates the stores and form action to make the form reactive. In order to use auto-subscriptions with the stores, call this function at the top-level scope of the component.

    Type parameters

    • Data: Record<string, unknown>

    • Ext: Obj = Obj

    Parameters

    • config: FormConfigWithInitialValues<Data> & Ext

      Configuration for the form itself. Since initialValues is set, Data will not be undefined

    Returns Form<Data>

  • Creates the stores and form action to make the form reactive. In order to use auto-subscriptions with the stores, call this function at the top-level scope of the component.

    Type parameters

    • Data: Record<string, unknown>

    • Ext: Obj = Obj

    Parameters

    • config: FormConfigWithoutInitialValues<Data> & Ext

      Configuration for the form itself. Since initialValues is not set (when only using the form action), Data will be undefined until the form element loads.

    Returns Form<Data | undefined>

Helper Functions

deepSet

  • deepSet<Data, Value>(obj: Data, value: Value): DeepSetResult<Data, Value>
  • Type parameters

    • Data: Obj

    • Value

    Parameters

    • obj: Data
    • value: Value

    Returns DeepSetResult<Data, Value>

deepSome

  • deepSome(obj: Obj, pred: (value: unknown) => boolean): boolean
  • Parameters

    • obj: Obj
    • pred: (value: unknown) => boolean
        • (value: unknown): boolean
        • Parameters

          • value: unknown

          Returns boolean

    Returns boolean

getPath

  • Parameters

    Returns string

isElement

  • isElement(el: Node): el is Element
  • Parameters

    • el: Node

    Returns el is Element

isFieldSetElement

  • isFieldSetElement(el: EventTarget): el is HTMLFieldSetElement
  • Parameters

    • el: EventTarget

    Returns el is HTMLFieldSetElement

isFieldValue

  • isFieldValue(value: unknown): value is FieldValue
  • Parameters

    • value: unknown

    Returns value is FieldValue

isFormControl

  • Parameters

    • el: EventTarget

    Returns el is FormControl

isInputElement

  • isInputElement(el: EventTarget): el is HTMLInputElement
  • Parameters

    • el: EventTarget

    Returns el is HTMLInputElement

isSelectElement

  • isSelectElement(el: EventTarget): el is HTMLSelectElement
  • Parameters

    • el: EventTarget

    Returns el is HTMLSelectElement

isTextAreaElement

  • isTextAreaElement(el: EventTarget): el is HTMLTextAreaElement
  • Parameters

    • el: EventTarget

    Returns el is HTMLTextAreaElement

Other Functions

executeValidation

setControlValue

  • Parameters

    Returns void

setForm

  • setForm<Data>(node: HTMLFormElement, data: Data): void
  • Sets the form inputs value to match the data object provided.

    Type parameters

    Parameters

    • node: HTMLFormElement
    • data: Data

    Returns void

Generated using TypeDoc