Field
The Field model returned by createField. All model properties are listed below. Most writable properties can be assigned directly, and @formily/reactive will respond and trigger UI updates.
Note
For process states like loading, validating, and submitting, direct assignment is not fully equivalent to the corresponding setXxx method. Prefer using setters.
Properties
| Property | Description | Type | Readonly | Default |
|---|---|---|---|---|
| initialized | Field initialized | Boolean | No | false |
| mounted | Field mounted | Boolean | No | false |
| unmounted | Field unmounted | Boolean | No | false |
| address | Field node path | FormPath | Yes | |
| path | Field data path | FormPath | Yes | |
| title | Field title | Any (determined by the TextType generic) | No | "" |
| description | Field description | Any (determined by the TextType generic) | No | "" |
| loading | Field loading state | Boolean | No | false |
| validating | Field validating | Boolean | No | false |
| submitting | Field submitting | Boolean | No | false |
| modified | Field subtree manually modified | Boolean | No | false |
| selfModified | Field itself manually modified | Boolean | No | false |
| active | Field active (focused) | Boolean | No | false |
| visited | Field visited | Boolean | No | false |
| inputValue | Field input value | Any | No | null |
| inputValues | Field input value set | Array | No | [] |
| dataSource | Field data source | Array | No | [] |
| validator | Field validator | FieldValidator | No | null |
| decorator | Field decorator | Any[] | No | null |
| component | Field component | Any[] | No | null |
| feedbacks | Field feedback info | IFieldFeedback | No | [] |
| parent | Parent field | GeneralField | Yes | null |
| errors | Field errors (aggregated + children) | IFormFeedback | Yes | [] |
| warnings | Field warnings (aggregated + children) | IFormFeedback | Yes | [] |
| successes | Field successes (aggregated + children) | IFormFeedback | Yes | [] |
| valid | Field valid (children included) | Boolean | Yes | true |
| invalid | Field invalid (children included) | Boolean | Yes | false |
| value | Field value | Any | No | |
| initialValue | Field initial value | Any | No | |
| display | Field display mode | FieldDisplayTypes | No | "visible" |
| pattern | Field interaction pattern | FieldPatternTypes | No | "editable" |
| required | Field required | Boolean | No | false |
| hidden | Field hidden | Boolean | No | false |
| visible | Field visible | Boolean | No | true |
| disabled | Field disabled | Boolean | No | false |
| readOnly | Field read-only | Boolean | No | false |
| readPretty | Field read-pretty | Boolean | No | false |
| editable | Field editable | Boolean | No | true |
| validateStatus | Field validation status | FieldValidateStatus | Yes | null |
| content | Field content, usually child nodes | any | No | null |
| data | Field extended property | Object | No | null |
| selfErrors | Field own error messages | FeedbackMessage | No | [] |
| selfWarnings | Field own warning messages | FeedbackMessage | No | [] |
| selfSuccesses | Field own success messages | FeedbackMessage | No | [] |
| selfValid | Field own valid | Boolean | Yes | true |
| selfInvalid | Field own invalid | Boolean | Yes | false |
| indexes | Field numeric index set | Number[] | Yes | - |
| index | Field numeric index, last of indexes | Number | Yes | - |
Detailed Explanations
active
Set to true on onFocus, set to false on onBlur.
visited
Once onFocus has been triggered, it stays true forever.
inputValue
The value collected when onInput is triggered.
inputValues
Multi-argument values collected when onInput is triggered.
loading / validating / submitting
These three states should preferably be updated via setLoading, setValidating, and setSubmitting. The corresponding setters handle internal timers and lifecycle events in addition to modifying the value; direct assignment only changes the current state value.
hidden
When true, display is hidden; when false, display is visible.
visible
When true, display is visible; when false, display is none.
Methods
setTitle
Description
Sets the field title.
Signature
interface setTitle {
(title?: any): void
}setDescription
Description
Sets the field description.
Signature
interface setDescription {
(title?: any): void
}setDataSource
Description
Sets the field data source.
Signature
interface setDataSource {
(dataSource?: FieldDataSource): void
}FieldDataSource reference: FieldDataSource
setFeedback
Description
Sets field feedback messages.
Signature
interface setFeedback {
(feedback?: IFieldFeedback): void
}IFieldFeedback reference: IFieldFeedback
setSelfErrors
Description
Sets the field's own error messages. Uses EffectError code for feedback updates to avoid polluting validator results. To force an override, use setFeedback.
Signature
interface setSelfErrors {
(messages?: FeedbackMessage): void
}setSelfWarnings
Description
Sets the field's own warning messages. Uses EffectWarning code for feedback updates to avoid polluting validator results. To force an override, use setFeedback.
Signature
interface setSelfWarnings {
(messages?: FeedbackMessage): void
}setSelfSuccesses
Description
Sets the field's own success messages. Uses EffectSuccess code for feedback updates to avoid polluting validator results. To force an override, use setFeedback.
Signature
interface setSelfSuccesses {
(messages?: FeedbackMessage): void
}setValidator
Description
Sets the field validator.
Signature
interface setValidator {
(validator?: FieldValidator): void
}FieldValidator reference: FieldValidator
setRequired
Description
Sets whether the field is required.
Signature
interface setRequired {
(required?: boolean): void
}setValidatorRule
Description
Sets a rule on the field validator. Similar to setRequired.
Signature
interface setValidatorRule {
(ruleName?: string, ruleValue: any): void
}setValue
Description
Sets the field value.
Signature
interface setValue {
(value?: FieldValue): void
}FieldValue reference: FieldValue
setInitialValue
Description
Sets the field initial value.
Signature
interface setInitialValue {
(initialValue?: FieldValue): void
}FieldValue reference: FieldValue
setDisplay
Description
Sets the field display mode.
Signature
interface setDisplay {
(display?: FieldDisplayTypes): void
}FieldDisplayTypes reference: FieldDisplayTypes
setPattern
Description
Sets the field interaction pattern.
Signature
interface setPattern {
(pattern?: FieldPatternTypes): void
}FieldPatternTypes reference: FieldPatternTypes
setLoading
Description
Sets the field loading state. Unlike directly writing field.loading = true, this method also handles internal delay and lifecycle notifications.
Signature
interface setLoading {
(loading?: boolean): void
}setValidating
Description
Sets the field validating state. Unlike directly writing field.validating = true, this method also handles runtime state and lifecycle notifications during validation.
Signature
interface setValidating {
(validating?: boolean): void
}setSubmitting
Description
Sets the field submitting state. Unlike directly writing field.submitting = true, this method also handles runtime state and lifecycle notifications during submission.
Signature
interface setSubmitting {
(submitting?: boolean): void
}setComponent
Description
Sets the field component.
Signature
interface setComponent {
(component?: FieldComponent, props?: any): void
}FieldComponent reference: FieldComponent
setComponentProps
Description
Sets field component properties.
Signature
interface setComponentProps {
(props?: any): void
}setDecorator
Description
Sets the field decorator.
Signature
interface setDecorator {
(decorator?: FieldDecorator, props?: any): void
}FieldDecorator reference: FieldDecorator
setDecoratorProps
Description
Sets field decorator properties.
Signature
interface setDecoratorProps {
(props?: any): void
}setState
Description
Sets field state.
Signature
interface setState {
(state: IFieldState): void
(callback: (state: IFieldState) => void): void
}IFieldState reference: IFieldState
getState
Description
Gets field state.
Signature
interface getState<T> {
(): IFieldState
(callback: (state: IFieldState) => T): T
}IFieldState reference: IFieldState
setData
Description
Sets the Data value.
Signature
interface setData {
(data: any): void
}setContent
Description
Sets the Content value.
Signature
interface setContent {
(content: any): void
}onInit
Description
Triggers field initialization. Normally does not need to be called manually.
Signature
interface onInit {
(): void
}onMount
Description
Triggers field mounting.
Signature
interface onMount {
(): void
}onUnmount
Description
Triggers field unmounting.
Signature
interface onUnmount {
(): void
}onInput
Description
Triggers field input.
Signature
interface onInput {
(...args: any[]): Promise<void>
}onFocus
Description
Triggers field focus.
Signature
interface onFocus {
(...args: any[]): Promise<void>
}onBlur
Description
Triggers field blur.
Signature
interface onBlur {
(...args: any[]): Promise<void>
}submit
Description
Triggers field submission (includes all child nodes, mainly for sub-form scenarios).
Signature
interface submit<T> {
(): Promise<Field['value']>
(onSubmit?: (values: Field['value']) => Promise<T> | void): Promise<T>
}validate
Description
Triggers field validation (includes all child nodes, mainly for sub-form scenarios).
Signature
interface validate {
(triggerType?: 'onInput' | 'onFocus' | 'onBlur'): Promise<IValidateResults>
}IValidateResults reference: IValidateResults
reset
Description
Triggers field reset (includes all child nodes, mainly for sub-form scenarios). If validation is set, the return is the validation result.
Signature
interface reset {
(options?: IFieldResetOptions): Promise<IValidateResults>
}IFieldResetOptions reference: IFieldResetOptions
IValidateResults reference: IValidateResults
query
Description
Queries fields. Can query neighboring fields relative to the current field.
Signature
interface query {
(pattern: FormPathPattern): Query
}FormPathPattern API reference: FormPath
Query object API reference: Query
queryFeedbacks
Description
Queries the current field's feedback info.
Signature
interface queryFeedbacks {
(search: ISearchFeedback): IFieldFeedback[]
}ISearchFeedback reference: ISearchFeedback
IFieldFeedback reference: IFieldFeedback
dispose
Description
Releases the observer. Normally does not need to be called manually.
Signature
interface dispose {
(): void
}destroy
Description
Releases the observer and removes the field model.
Signature
interface destroy {
(): void
}match
Description
Matches fields by path pattern.
Signature
interface match {
(pattern: FormPathPattern): boolean
}FormPathPattern API reference: FormPath
inject
Description
Injects executable methods into the field model.
Signature
interface inject {
(actions: Record<string, (...args: any[]) => any>): void
}invoke
Description
Calls an executable method injected into the field model via inject.
Signature
interface invoke {
(name: string, ...args: any[]): any
}Types
Note: if you want to consume these types manually, export them directly from the package module.
FieldValidator
For complete documentation, see the Validation Rules chapter in the @silver-formily/validator docs.
// String format validator
type ValidatorFormats
= | 'url'
| 'email'
| 'ipv6'
| 'ipv4'
| 'number'
| 'integer'
| 'idcard'
| 'qq'
| 'phone'
| 'money'
| 'zh'
| 'date'
| 'zip'
| (string & {}) // other format validators must be registered via registerValidateFormats
// Object validation result
interface IValidateResult {
type: 'error' | 'warning' | 'success' | (string & {})
message: string
}
// Object validator
interface IValidatorRules<Context = any> {
triggerType?: 'onInput' | 'onFocus' | 'onBlur'
format?: ValidatorFormats
validator?: ValidatorFunction<Context>
required?: boolean
pattern?: RegExp | string
max?: number
maximum?: number
exclusiveMaximum?: number
exclusiveMinimum?: number
minimum?: number
min?: number
len?: number
whitespace?: boolean
enum?: any[]
const?: any
multipleOf?: number
uniqueItems?: boolean
maxProperties?: number
minProperties?: number
maxItems?: number
maxLength?: number
minItems?: number
minLength?: number
message?: string
[key: string]: any // other properties must be registered via registerValidateRules
}
// Function validator result type
type ValidatorFunctionResponse = null | string | boolean | IValidateResult
// Function validator
type ValidatorFunction<Context = any> = (
value: any,
rule: IValidatorRules<Context>,
ctx: Context
) => ValidatorFunctionResponse | Promise<ValidatorFunctionResponse> | null
// Non-array validator
type ValidatorDescription
= | ValidatorFormats
| ValidatorFunction<Context>
| IValidatorRules<Context>
// Array validator
type MultiValidator<Context = any> = ValidatorDescription<Context>[]
type FieldValidator<Context = any>
= | ValidatorDescription<Context>
| MultiValidator<Context>FeedbackMessage
type FeedbackMessage = any[]The feedback message collection in the current source code is defined directly as any[]. This means the core layer does not restrict message content to strings; the exact rendering strategy is determined by the upper UI adapter.
FieldDataSource
type FieldDataSource = Array<{
label?: any
value?: any
title?: any
key?: any
text?: any
children?: FieldDataSource
[key: string]: any
}>The field data source is essentially an array; the content format is up to the user. We recommend using the label/value format. Note that in UI frameworks, setting it does not automatically take effect — the dataSource property must be bound to a specific UI component. For example, in @formily/react, use the connect function to bind state, or consume it directly inside a component via useField.
FieldValue
The field value type is essentially Any. Note that in an ArrayField it is forced to be an array type, and in an ObjectField it is forced to be an object type.
FieldComponent
type FieldComponent<Component extends JSXComponent, ComponentProps = any>
= | [Component]
| [Component, ComponentProps]
| boolean
| any[]In the core layer, field components are stored as runtime configuration slots, typically passed as [Component, Props] tuples. They also accept boolean or other array forms for interpretation by upper adapters.
FieldDecorator
type FieldDecorator<Decorator extends JSXComponent, DecoratorProps = any>
= | [Decorator]
| [Decorator, DecoratorProps]
| boolean
| any[]The storage form of field decorators is the same as FieldComponent — runtime configuration data, not limited to strings or component constructors.
FieldReaction
type FieldReaction = (field: GeneralField) => voidFieldDisplayTypes
type FieldDisplayTypes = 'none' | 'hidden' | 'visible' | ({} & string)FieldPatternTypes
type FieldPatternTypes
= | 'editable'
| 'readOnly'
| 'disabled'
| 'readPretty'
| ({} & string)FieldValidateStatus
type FieldValidateStatus = 'error' | 'warning' | 'success' | 'validating'GeneralField
type GeneralField = Field | VoidField | ArrayField | ObjectFieldVoidField reference: VoidField
ArrayField reference: ArrayField
ObjectField reference: ObjectField
IFieldFeedback
interface IFieldFeedback {
triggerType?: 'onInput' | 'onFocus' | 'onBlur' // validation trigger type
type?: 'error' | 'success' | 'warning' // feedback type
code?: // feedback code
| 'ValidateError'
| 'ValidateSuccess'
| 'ValidateWarning'
| 'EffectError'
| 'EffectSuccess'
| 'EffectWarning'
| (string & {})
messages?: FeedbackMessage // feedback messages
}ISearchFeedback
interface ISearchFeedback {
triggerType?: 'onInput' | 'onFocus' | 'onBlur' // validation trigger type
type?: 'error' | 'success' | 'warning' // feedback type
code?: // feedback code
| 'ValidateError'
| 'ValidateSuccess'
| 'ValidateWarning'
| 'EffectError'
| 'EffectSuccess'
| 'EffectWarning'
| (string & {})
address?: FormPathPattern
path?: FormPathPattern
messages?: FeedbackMessage
}IFieldState
interface IFieldState {
selfDisplay?: FieldDisplayTypes
selfPattern?: FieldPatternTypes
content?: any
data?: any
decoratorType?: any
decoratorProps?: Record<string, any>
componentType?: any
componentProps?: Record<string, any>
designable?: boolean
hidden?: boolean
visible?: boolean
editable?: boolean
readOnly?: boolean
disabled?: boolean
readPretty?: boolean
title?: any
description?: any
loading?: boolean
validating?: boolean
submitting?: boolean
selfModified?: boolean
modified?: boolean
active?: boolean
visited?: boolean
inputValue?: FieldValue
inputValues?: any[]
initialized?: boolean
dataSource?: FieldDataSource
mounted?: boolean
unmounted?: boolean
validator?: FieldValidator
decorator?: FieldDecorator
component?: FieldComponent
feedbacks?: IFieldFeedback[]
errors?: IFormFeedback[]
warnings?: IFormFeedback[]
successes?: IFormFeedback[]
selfErrors?: FeedbackMessage
selfWarnings?: FeedbackMessage
selfSuccesses?: FeedbackMessage
selfValid?: boolean
selfInvalid?: boolean
valid?: boolean
invalid?: boolean
value?: FieldValue
initialValue?: FieldValue
display?: FieldDisplayTypes
pattern?: FieldPatternTypes
required?: boolean
validateStatus?: 'error' | 'success' | 'warning' | 'validating'
index?: number
indexes?: number[]
}IGeneralFieldState
type IGeneralFieldState = IFieldState & IVoidFieldStateIVoidFieldState reference: IVoidFieldState
FieldMatchPattern
type FieldMatchPattern = FormPathPattern | Query | GeneralFieldQuery reference: Query
IFieldResetOptions
interface IFieldResetOptions {
forceClear?: boolean // force clear
validate?: boolean // validate
}IValidateResults
interface IValidateResults {
error?: string[]
warning?: string[]
success?: string[]
}Formily TypeScript Type Convention
- Simple non-object data types or union types use
typeand must not start with an uppercaseI.- Simple object types use
interfaceand start with an uppercaseI. Combinations of different interfaces (Intersection or Extends) usetype, also starting with an uppercaseI.