Skip to main content

JS API

API

formApi

NameTypeDescription
nodeHTML ElementForm root DOM element.
on(eventType, callback) => voidListen to the form event
off(eventType, callback) => voidUnlisten to the form event
getData() => objectGet all data for the form
setData(newData) => voidReplace all data in the form with newData
getDataWithPreprocessor() => objectGet the data that the form has been processed and can be submitted to the backend
getContext() => objectObtain the upper and lower information, such as userProfile, etc.
getValue(id) => anyGet the value of a single field
setValue(id, newValue) => voidSet the value of a single field
getInitialValues() => objectGet all the data at the beginning of the form
setInitialValue(id, initialValue, notReplaceValue) => anySet the value of a single field, by default, the current value of the changed field will be replaced together, and 'notReplaceValue' can be set to 'true' to only set the initial value without replacing the current value
getErrors() => objectGet all error messages for the form
setErrors(errors) => voidSet Form Error Message
setError(id, error) => voidSet the error message
getFieldApis() => objectGet all available fields API
getFieldApi(id) => objectTo get the API of a single field, the API exposed by each component is different, for example, EditableTable, please refer to the API documentation for each component
validateForm() => PromiseImmediately verify that the current form data is valid, and the return value of Promise then is errors
isDataValid() => booleanWhether the current form data is valid
isDirty() => booleanWhether the current form data has been modified
registerMethod(name, func) => voidRegister the function, and the Button's 'call formMethod' action can be called to
getMethods() => objectGet all registered functions
setFieldComponentProps(id, componentProps) => voidBy dynamically setting the componentProps of a component by JS, you can solve the problem that callbacks cannot be written in json mode, and the properties of many components are in the form of callbacks.
submit({ saveOnly, handler }) => PromiseSubmit Form
refresh() => voidRefresh the form
cancel() => voidCancel and go back to the previous page
reset({ initialValues }) => voidRemake form data
getProps() => objectGet all the properties of the form

formApi.on eventType

NamecallbackDescription
firstRendered(formApi) => voidCall this function when the form is rendered for the first time
ready(formApi) => voidWhen the form API and all asynchronous component APIs are available
unmount() => voidCalled when the form is unloaded
fieldValueChange(id, newValue) => voidWhen a field value changes, the parameter is a single form data
change(Object) => voidWhen the form data changes, the parameters are all form data
validationFail(Object) => voidWhen form verification fails, the parameters are all error messages in the form
schemaChanged(Object) => voidCall this function when the form schema changes
submitted(Object) => voidCall this function after the form submits data successfully

restApi

NameType
get(url, config) => Promise
getStatic(url, config) => Promise
post(url, data, config) => Promise
put(url, data, config) => Promise
delete(url, config) => Promise

messageApi

https://ant.design/components/message#api