FormItem doesn't detect control input inside
See original GitHub issueEnvironment
- antd version: 2.7.4
- OS and its version: OS X 10.12.3
- Browser and its version: Chrome 56
What did you do? Please provide steps to re-produce your problem.
We wrap our form fields into their own component which contain their validation logic. Example
UsernameInput.js
class UsernameInput extends Component {
render() {
return this.props.form.getFieldDecorator(this.props.id, {
rules: [...]
})(InputComponent);
}
}
And we want to use them in our forms like this
// imports here
class CustomForm {
render() {
return (<Form>
<Form.Item>
<UsernameInput form={this.props.form} />
</Form.Item>
</Form>);
}
}
export default Form.create()(CustomForm);
This doesn’t work because FormItem.getControls doesn’t detect the component as a control. Just sees the wrapper as UsernameInput.
What do you expected?
FormItem
to detect UsernameInput
and work as any input control. Show error messages, feedback, helps, etc.
What happen?
FormItem
doesn’t find the control inside.
Issue Analytics
- State:
- Created 6 years ago
- Comments:8 (5 by maintainers)
Top Results From Across the Web
Ant.design does not detect custom input component in Form ...
You need to pass to your custom component all props, because Form.Item pass to there onChange and value props function CustomInput({size ...
Read more >Controller | React Hook Form - Simple React forms validation
This simplifies integrating with external controlled components with non-standard prop names. Provides onChange , onBlur , name , ref and value to the...
Read more >Form - Ant Design
This demo shows how to use Form.Item with multiple controls. <Form.Item name="field" /> will only bind the control(Input/Select) which ...
Read more >ASP.NET Core Blazor forms and input components
Learn how to use forms with field validation and built-in input components in Blazor.
Read more >Using Material UI with React Hook Form - LogRocket Blog
We have already seen that we need these two things to control almost any input. Refactoring our form. So let's see if the...
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
We solved this by calling the component as a function
CustomForm.js
But if you’re open to ideas, I think a possible solution would be to define a context in the
FormItem
and theInput
can register themselves when it’s present. ExampleFormItem.js
Input.js
@gaastonsr Your solution help me a lot!
Is this is a still valid issue? The context suggestion sounds good to me.