form.resetFields() can's clear the Select 's value
See original GitHub issueVersion
2.13.10
Environment
chrome nodev8.0
Reproduction link
https://codepen.io/pssgo/pen/OOorwq
Steps to reproduce
import React from 'react'
import { Form, Select, Button } from 'antd'
const Option = Select.Option
const FormItem = Form.Item
class Node extends React.Component {
reset = () => {
this.props.form.resetFields()
}
render() {
const { form } = this.props
return (
<Form>
<FormItem label="todo">
{form.getFieldDecorator('todo', {
valuePropName: 'selected',
})(
<Select allowClear>
<Option value="a">1</Option>
<Option value="b">2</Option>
</Select>,
)}
</FormItem>
<Button type="primary" onClick={this.reset}>
reset
</Button>
</Form>
)
}
}
export default Form.create()(Node)
What is expected?
form.resetFields() can clear the Select 's value
What is actually happening?
form.resetFields() can’t clear the Select 's value
Issue Analytics
- State:
- Created 6 years ago
- Reactions:6
- Comments:12 (2 by maintainers)
Top Results From Across the Web
Clear form input field values after submitting in react js with ant ...
We can clear the form data using the resetFields function present in form ... the default value, you can specify it using setFieldsValue()....
Read more >form.resetFields() can's clear the Select 's value #8349
What is actually happening? · I removed valuePropName: 'selected' and it works fine now. Can you show the code with valuePropName · I'm...
Read more >useForm - reset - React Hook Form
An optional object to reset form values, and it's recommended to provide the entire defaultValues when supplied. keepErrors, boolean. All errors will remain....
Read more >Form - Ant Design
High performance Form component with data scope management. Including data collection, verification, and styles.
Read more >HTMLFormElement.reset() - Web APIs | MDN
The HTMLFormElement.reset() method restores a form element's default values. This method does the same thing as clicking the form's <input ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Use this - this.props.form.resetFields()
I’ve been using key={Math.random()} to force reset. Not the best, but it works.