Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AntDesign表单Form实例方法(useForm/ref) #5

Open
machao07 opened this issue Feb 17, 2022 · 0 comments
Open

AntDesign表单Form实例方法(useForm/ref) #5

machao07 opened this issue Feb 17, 2022 · 0 comments

Comments

@machao07
Copy link
Owner

image

1、获取表单实例

函数式组件

const AppletModal: React.FC<any> = (props) => {
    const [form] = Form.useForm();
    render(){
		return(
			<Form ref={form}></Form>
		)
	}
}

class类组件

import { FormInstance } from 'antd/lib/form';

class AppletEdit extends React.Component<any, any> {
    form: any = React.createRef();
    form = React.createRef<FormInstance>();
    render(){
		return(
			<Form ref={this.form}></Form>
		)
	}
}

2、form表单实例方法

给表单属性赋值 ref

函数式组件

form.setFieldsValue({
    bankIdList: options.map((v) => {
        return v.value;
    })
})

class组件

this.form.current.setFieldsValue({
    bankIdList: options.map((v) => {
        return v.value;
    })
})

3、打印 console.log(form)

image

1)获取所有表单属性值

返回一个json对象
this.form.current.getFieldsValue()

2) 设置表单属性值

this.form.current.setFieldsValue({ xxx: xxx })

更多

其他相关FormInstance说明及使用方法文档

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant