Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Form<T>

Type parameters

  • T: {}

Hierarchy

Index

Constructors

constructor

  • Type parameters

    • T: {}

    Parameters

    Returns Form<T>

  • Type parameters

    • T: {}

    Parameters

    Returns Form<T>

Properties

context

context: any

If using the new style context, re-declare this in your class to be the React.ContextType of your static contextType. Should be used with type annotation or static contextType.

static contextType = MyContext
// For TS pre-3.7:
context!: React.ContextType<typeof MyContext>
// For TS 3.7 and above:
declare context: React.ContextType<typeof MyContext>
see

https://reactjs.org/docs/context.html

Readonly formRef

formRef: RefObject<HTMLFormElement> = ...

Readonly props

props: Readonly<IFormProps<T>> & Readonly<{ children?: ReactNode }>

refs

refs: {}

Type declaration

  • [key: string]: ReactInstance

state

state: Readonly<{}>

Static CombineErrors

CombineErrors: typeof CombineErrors = ...

Static FieldSetValue

FieldSetValue: (__namedParameters: IFieldSetValueProps) => Element = ...

Type declaration

    • (__namedParameters: IFieldSetValueProps): Element
    • 根据 name 订阅 FieldSet 的值

      Parameters

      • __namedParameters: IFieldSetValueProps

      Returns Element

Static FieldValid

FieldValid: <T>(props: IFieldValidProps<T>) => React.ReactElement | null = ...

Type declaration

    • <T>(props: IFieldValidProps<T>): React.ReactElement | null
    • 根据 name 或者 model 订阅字段校验状态的更新

      当参数是 Model 对象时不依赖 FormContext,参数是字段名时必须在有 FormContext 的环境下使用。

      Type parameters

      • T

      Parameters

      • props: IFieldValidProps<T>

      Returns React.ReactElement | null

Static FieldValue

FieldValue: <T>(props: IFieldValueProps<T>) => React.ReactElement | null = ...

Type declaration

    • <T>(props: IFieldValueProps<T>): React.ReactElement | null
    • 根据 name 或者 model 订阅字段值的更新

      Type parameters

      • T

      Parameters

      • props: IFieldValueProps<T>

      Returns React.ReactElement | null

Static TouchWhen

TouchWhen: typeof TouchWhen = ...

Static ValidateOccasion

ValidateOccasion: typeof ValidateOccasion = ...

Static ValidateOption

ValidateOption: typeof ValidateOption = ...

Static array

array: <ChildBuilder>(childBuilder: ChildBuilder) => FieldArrayBuilder<ChildBuilder> = ...

Type declaration

    • 创建一个 FieldArray builder

      Type parameters

      Parameters

      • childBuilder: ChildBuilder

        数组元素的 builder 对象,可以是 fieldarray 或者 set 的返回值

      Returns FieldArrayBuilder<ChildBuilder>

Static Optional contextType

contextType: Context<any>

If set, this.context will be set at runtime to the current value of the given Context.

Usage:

type MyContext = number
const Ctx = React.createContext<MyContext>(0)

class Foo extends React.Component {
  static contextType = Ctx
  context!: React.ContextType<typeof Ctx>
  render () {
    return <>My context's value: {this.context}</>;
  }
}
see

https://reactjs.org/docs/context.html#classcontexttype

Static createAsyncValidator

createAsyncValidator: <T>(validator: (value: T, context: ValidatorContext<T>) => null | Observable<IMaybeError<T>> | Promise<IMaybeError<T>>) => IAsyncValidator<T> = ...

Type declaration

Static displayName

displayName: string = 'ZentForm'

Static field

field: <T>(defaultValue: T) => FieldBuilder<T> = ...

Type declaration

    • 创建一个 Field builder

      Type parameters

      • T

      Parameters

      • defaultValue: T

        Field 的默认值

      Returns FieldBuilder<T>

Static form

form: <ChildBuilders>(childBuilders: ChildBuilders) => FormBuilder<ChildBuilders> = ...

Type declaration

    • <ChildBuilders>(childBuilders: ChildBuilders): FormBuilder<ChildBuilders>
    • 创建一个 Form builder,是最顶层的 builder 对象

      Type parameters

      • ChildBuilders: UnknownFieldSetBuilderChildren

      Parameters

      • childBuilders: ChildBuilders

        Form 每个字段对应的 builder 对象,其值可以是 fieldarray 或者 set 的返回值

      Returns FormBuilder<ChildBuilders>

Static isAsyncValidator

isAsyncValidator: <T>(validator: ISyncValidator<T> | IAsyncValidator<T>) => validator is IAsyncValidator<T> = ...

Type declaration

Static set

set: <ChildBuilders>(childBuilders: ChildBuilders) => FieldSetBuilder<ChildBuilders> = ...

Type declaration

    • <ChildBuilders>(childBuilders: ChildBuilders): FieldSetBuilder<ChildBuilders>
    • 创建一个 FieldSet builder

      Type parameters

      • ChildBuilders: UnknownFieldSetBuilderChildren

      Parameters

      • childBuilders: ChildBuilders

        FieldSet 每个字段对应的 builder 对象,其值可以是 fieldarray 或者 set 的返回值

      Returns FieldSetBuilder<ChildBuilders>

Static useField

useField: { <Value>(field: string | ModelRef<Value, any, FieldModel<Value>>, defaultValue: Value | (() => Value), validators?: IValidators<Value>): FieldModel<Value>; <Value>(field: FieldModel<Value> | ModelRef<Value, any, FieldModel<Value>>): FieldModel<Value> } = ...

Type declaration

    • 获取一个 Field

      Model 模式下传入字符串类型的 field 时, validatorsdefaultValue 均无效。

      Type parameters

      • Value

      Parameters

      • field: string | ModelRef<Value, any, FieldModel<Value>>

        字段名

      • defaultValue: Value | (() => Value)

        默认值

      • Optional validators: IValidators<Value>

        校验函数数组

      Returns FieldModel<Value>

    • 获取一个 Field

      Type parameters

      • Value

      Parameters

      • field: FieldModel<Value> | ModelRef<Value, any, FieldModel<Value>>

        Field 对应的 model 对象,用于关联 Field 和 model;当 FormStrategyModel 或渲染 FieldArray 的时候才能使用

      Returns FieldModel<Value>

Static useFieldArray

useFieldArray: { <Item, Child>(field: string | ModelRef<readonly Item[], any, FieldArrayModel<Item, Child>>, validators?: IValidators<readonly (Item | null)[]>, defaultValue?: Item[]): FieldArrayModel<Item, Child>; <Item, Child>(field: FieldArrayModel<Item, Child>): FieldArrayModel<Item, Child> } = ...

Type declaration

    • 创建一个 FieldArray

      Model 模式下传入字符串类型的 field 时, validatorsdefaultValue 均无效。

      Type parameters

      • Item

      • Child: IModel<Item, Child>

      Parameters

      • field: string | ModelRef<readonly Item[], any, FieldArrayModel<Item, Child>>

        字段名

      • Optional validators: IValidators<readonly (Item | null)[]>

        校验函数数组

      • Optional defaultValue: Item[]

        默认值

      Returns FieldArrayModel<Item, Child>

    • 创建一个 FieldArray

      Type parameters

      • Item

      • Child: IModel<Item, Child>

      Parameters

      • field: FieldArrayModel<Item, Child>

        FieldArray 对应的 model 对象,用于关联 FieldArray 和 model;当 FormStrategyModel 的时候才能用

      Returns FieldArrayModel<Item, Child>

Static useFieldArrayChildModels

useFieldArrayChildModels: <Item, Child>(field: string | FieldArrayModel<Item, Child>) => Child[] | null = ...

Type declaration

    • <Item, Child>(field: string | FieldArrayModel<Item, Child>): Child[] | null
    • 根据 name 或者 model 订阅 FieldArray 的更新

      Type parameters

      • Item

      • Child: IModel<Item, Child>

      Parameters

      Returns Child[] | null

Static useFieldArrayValue

useFieldArrayValue: <Item, Child>(field: string | FieldArrayModel<Item, Child>) => Child[] | null = ...
deprecated

Renamed to useFieldArrayChildModels

Type declaration

    • <Item, Child>(field: string | FieldArrayModel<Item, Child>): Child[] | null
    • 根据 name 或者 model 订阅 FieldArray 的更新

      Type parameters

      • Item

      • Child: IModel<Item, Child>

      Parameters

      Returns Child[] | null

Static useFieldSet

useFieldSet: { <T>(field: string | ModelRef<$FieldSetValue<T>, any, FieldSetModel<T>>, validators?: IValidators<$FieldSetValue<T>>): IUseFieldSet<T>; <T>(field: FieldSetModel<T>): IUseFieldSet<T> } = ...

Type declaration

    • 创建一个 FieldSet

      Model 模式下传入字符串类型的 field 时, validators 无效。

      Type parameters

      • T: UnknownFieldSetModelChildren

      Parameters

      Returns IUseFieldSet<T>

    • 创建一个 FieldSet

      Type parameters

      • T: UnknownFieldSetModelChildren

      Parameters

      Returns IUseFieldSet<T>

Static useFieldValid

useFieldValid: <T>(field: string | IModel<T>) => boolean | null = ...

Type declaration

    • <T>(field: string | IModel<T>): boolean | null
    • 订阅 model 的校验状态

      当参数是 Model 对象时不依赖 FormContext,参数是字段名时必须在有 FormContext 的环境下使用。

      Type parameters

      • T

      Parameters

      • field: string | IModel<T>

      Returns boolean | null

Static useFieldValue

useFieldValue: <T>(field: string | IModel<T>) => T | null = ...

Type declaration

    • <T>(field: string | IModel<T>): T | null
    • 订阅 model 的值。 当参数是 Model 对象时不依赖 FormContext,参数是字段名时必须在有 FormContext 的环境下使用。

      Type parameters

      • T

      Parameters

      • field: string | IModel<T>

      Returns T | null

Static useForm

useForm: <T>(arg: View | FormBuilder<T>) => ZentForm<$FieldSetBuilderChildren<T>> = ...

Type declaration

Static useFormValid

useFormValid: <T>(form: ZentForm<T>) => boolean = ...

Type declaration

    • <T>(form: ZentForm<T>): boolean
    • Subscribe value of form. Note that this hook might cause performance problem(s), use it with caution.

      Type parameters

      • T: UnknownFieldSetModelChildren

      Parameters

      • form: ZentForm<T>

        Return value of Form.useForm

      Returns boolean

Static useFormValue

useFormValue: <T>(form: ZentForm<T>, defaultValue?: $FieldSetValue<T>) => $FieldSetValue<T> = ...

Type declaration

    • Subscribe value of form. Note that this hook might cause performance problem(s), use it with caution.

      Type parameters

      • T: UnknownFieldSetModelChildren

      Parameters

      • form: ZentForm<T>

        Return value of Form.useForm

      • Optional defaultValue: $FieldSetValue<T>

      Returns $FieldSetValue<T>

Static useModelValid

useModelValid: <T>(model: IModel<T>) => boolean | null = ...

Type declaration

    • <T>(model: IModel<T>): boolean | null
    • 订阅 model 的校验状态

      deprecated

      Use useFieldValid

      Type parameters

      • T

      Parameters

      • model: IModel<T>

      Returns boolean | null

Static useModelValue

useModelValue: <T>(model: IModel<T>) => T | null = ...

Type declaration

    • <T>(model: IModel<T>): T | null
    • 订阅 model 的值

      deprecated

      Use useFieldValue

      Type parameters

      • T

      Parameters

      • model: IModel<T>

      Returns T | null

Static useNamedChildModel

useNamedChildModel: <T, K>(fieldSet: FieldSetModel<T>, name: K) => T[K] = ...

Type declaration

    • 订阅名为 name 的子 model 变更。 变更包括增加/删除该子 model,但不包括子 model 内部数据的变化。

      Type parameters

      • T: UnknownFieldSetModelChildren

      • K: string | number | symbol = keyof T

      Parameters

      • fieldSet: FieldSetModel<T>

        订阅 child 的 FieldSetModel

      • name: K

        child 的名字

      Returns T[K]

Methods

Optional UNSAFE_componentWillMount

  • UNSAFE_componentWillMount(): void

Optional UNSAFE_componentWillReceiveProps

  • UNSAFE_componentWillReceiveProps(nextProps: Readonly<IFormProps<T>>, nextContext: any): void

Optional UNSAFE_componentWillUpdate

  • UNSAFE_componentWillUpdate(nextProps: Readonly<IFormProps<T>>, nextState: Readonly<{}>, nextContext: any): void

Optional componentDidCatch

  • componentDidCatch(error: Error, errorInfo: ErrorInfo): void
  • Catches exceptions generated in descendant components. Unhandled exceptions will cause the entire component tree to unmount.

    Parameters

    • error: Error
    • errorInfo: ErrorInfo

    Returns void

componentDidMount

  • componentDidMount(): void

componentDidUpdate

  • componentDidUpdate(prevProps: IFormProps<T>): void

Optional componentWillMount

  • componentWillMount(): void

Optional componentWillReceiveProps

  • componentWillReceiveProps(nextProps: Readonly<IFormProps<T>>, nextContext: any): void

componentWillUnmount

  • componentWillUnmount(): void

Optional componentWillUpdate

  • componentWillUpdate(nextProps: Readonly<IFormProps<T>>, nextState: Readonly<{}>, nextContext: any): void

forceUpdate

  • forceUpdate(callback?: () => void): void
  • Parameters

    • Optional callback: () => void
        • (): void
        • Returns void

    Returns void

Optional getSnapshotBeforeUpdate

  • getSnapshotBeforeUpdate(prevProps: Readonly<IFormProps<T>>, prevState: Readonly<{}>): any
  • Runs before React applies the result of render to the document, and returns an object to be given to componentDidUpdate. Useful for saving things such as scroll position before render causes changes to it.

    Note: the presence of getSnapshotBeforeUpdate prevents any of the deprecated lifecycle events from running.

    Parameters

    • prevProps: Readonly<IFormProps<T>>
    • prevState: Readonly<{}>

    Returns any

render

  • render(): Element

scrollToFirstError

  • scrollToFirstError(): void

setState

  • setState<K>(state: {} | ((prevState: Readonly<{}>, props: Readonly<IFormProps<T>>) => {} | Pick<{}, K>) | Pick<{}, K>, callback?: () => void): void
  • Type parameters

    • K: never

    Parameters

    • state: {} | ((prevState: Readonly<{}>, props: Readonly<IFormProps<T>>) => {} | Pick<{}, K>) | Pick<{}, K>
    • Optional callback: () => void
        • (): void
        • Returns void

    Returns void

Optional shouldComponentUpdate

  • shouldComponentUpdate(nextProps: Readonly<IFormProps<T>>, nextState: Readonly<{}>, nextContext: any): boolean
  • Called to determine whether the change in props and state should trigger a re-render.

    Component always returns true. PureComponent implements a shallow comparison on props and state and returns true if any props or states have changed.

    If false is returned, Component#render, componentWillUpdate and componentDidUpdate will not be called.

    Parameters

    • nextProps: Readonly<IFormProps<T>>
    • nextState: Readonly<{}>
    • nextContext: any

    Returns boolean

Generated using TypeDoc