question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

form.resetFields() can's clear the Select 's value

See original GitHub issue

Version

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:closed
  • Created 6 years ago
  • Reactions:6
  • Comments:12 (2 by maintainers)

github_iconTop GitHub Comments

48reactions
anandwebscommented, Mar 4, 2019

Use this - this.props.form.resetFields()

6reactions
mikeaustincommented, Apr 24, 2020

I’ve been using key={Math.random()} to force reset. Not the best, but it works.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found