setFieldsValue not working while trying update onchange same form item
See original GitHub issuesetFieldsValue not working while trying update onchange same form item. (** If I am trying set value different form item its working )
not working
this.props.form.setFieldsValue({
test: 100,
});
working
this.props.form.setFieldsValue({
otherFormItem: 100,
});
Complete Code
@import React, { Component } from 'react'
import { connect } from 'react-redux'
import { Form, Input } from 'antd';
const FormItem = Form.Item;
@connect()
class TestForm extends React.Component {
handleChange = (e) => {
console.log(e.target.value);
console.log("before", this.props.form.getFieldsValue().test);
if (e.target.value > 100) {
this.props.form.setFieldsValue({
test: 100,
});
}
console.log("after", this.props.form.getFieldsValue().test);
}
render() {
const { getFieldDecorator } = this.props.form;
const formItemLayout = 'vertical';
return (
<Form>
<br/>
<FormItem label="Test " {...formItemLayout} >
{getFieldDecorator('test', {rules: [{ required: true, message: 'Please input your test !', }], onChange: this.handleChange, })(
<Input placeholder="test" />
)}
</FormItem>
<FormItem label="otherFormItem " {...formItemLayout} >
{getFieldDecorator('otherFormItem', {rules: [{ required: true, message: 'Please input your !', }], onChange: this.handleChange, })(
<Input placeholder="otherFormItem" />
)}
</FormItem>
</Form>
)
}
}
const Test = Form.create({})(TestForm);
export default Test
Issue Analytics
- State:
- Created 7 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Antd form setFieldValue on OnChange event is not working
I am trying to show the formatted value in the same text field. Please find the sandbox link here codeSandbox. I dont want...
Read more >useForm - setValue - React Hook Form
This function allows you to dynamically set the value of a registered field and have the options to validate and update the form...
Read more >Form - Ant Design
Does not work when multiple Item with same name setting the initialValue. Why does onFieldsChange trigger three times on change when field sets...
Read more >an antd bug of form setFieldsValue - CodePen
... is using the 'http' protocol, which may not work when the browser is using https. ... const {Form, Input, Select} = antd....
Read more >form item checkbox antd | The search engine you control.
setFieldsValue if you cant't change using upper code. for functional component you have to take the form reference that is binding using useForm()...
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
@daskyrk Here is how:
@iiitmahesh have you find out how to use
getValueFromEvent
?