admin管理员组文章数量:1355540
In reactjs, I am using the ant-design
library for a form. In the console i face this problem:
Warning: validateDOMNesting(...): <form> cannot appear as a descendant of <form>
Can someone show me what mistake I made in my code?
code
import React, { ponent } from 'react';
import styled from 'styled-ponents';
import 'antd/dist/antd.css';
import './FirstStep.css';
import { Form, Input } from 'antd';
class RegisterStepOne extends React.Component {
render() {
const { getFieldDecorator } = this.props;
return (
<div>
<FormCard>
<Form onSubmit={this.handleSubmit} className="login-form">
<FormItem>
{getFieldDecorator('firstName', {
rules: [
{
required: true,
message: 'Please input your First name!',
whitespace: true,
},
],
})(<Input placeholder="First name" />)}
</FormItem>
<FormItem>
{getFieldDecorator('lastName', {
rules: [
{
required: true,
message: 'Please input your Last name!',
whitespace: true,
},
],
})(<Input placeholder="Last name" />)}
</FormItem>
<FormItem>
{getFieldDecorator('email', {
rules: [
{
type: 'email',
message: 'The input is not valid E-mail!',
},
{
required: true,
message: 'Please input your E-mail!',
},
],
})(<Input placeholder="Email" />)}
</FormItem>
<FormItem>
{getFieldDecorator('lastPosition', {
rules: [
{
required: true,
message: 'Please input your Last Position!',
whitespace: true,
},
],
})(<Input placeholder="Present or last position" />)}
</FormItem>
<FormItem>
{getFieldDecorator('lastCompany', {
rules: [
{
required: true,
message: 'Please input your Last Company!',
whitespace: true,
},
],
})(<Input placeholder="Present or last Company" />)}
</FormItem>
</Form>
</FormCard>
</div>
);
}
}
export default RegisterStepOne;
In reactjs, I am using the ant-design
library for a form. In the console i face this problem:
Warning: validateDOMNesting(...): <form> cannot appear as a descendant of <form>
Can someone show me what mistake I made in my code?
code
import React, { ponent } from 'react';
import styled from 'styled-ponents';
import 'antd/dist/antd.css';
import './FirstStep.css';
import { Form, Input } from 'antd';
class RegisterStepOne extends React.Component {
render() {
const { getFieldDecorator } = this.props;
return (
<div>
<FormCard>
<Form onSubmit={this.handleSubmit} className="login-form">
<FormItem>
{getFieldDecorator('firstName', {
rules: [
{
required: true,
message: 'Please input your First name!',
whitespace: true,
},
],
})(<Input placeholder="First name" />)}
</FormItem>
<FormItem>
{getFieldDecorator('lastName', {
rules: [
{
required: true,
message: 'Please input your Last name!',
whitespace: true,
},
],
})(<Input placeholder="Last name" />)}
</FormItem>
<FormItem>
{getFieldDecorator('email', {
rules: [
{
type: 'email',
message: 'The input is not valid E-mail!',
},
{
required: true,
message: 'Please input your E-mail!',
},
],
})(<Input placeholder="Email" />)}
</FormItem>
<FormItem>
{getFieldDecorator('lastPosition', {
rules: [
{
required: true,
message: 'Please input your Last Position!',
whitespace: true,
},
],
})(<Input placeholder="Present or last position" />)}
</FormItem>
<FormItem>
{getFieldDecorator('lastCompany', {
rules: [
{
required: true,
message: 'Please input your Last Company!',
whitespace: true,
},
],
})(<Input placeholder="Present or last Company" />)}
</FormItem>
</Form>
</FormCard>
</div>
);
}
}
export default RegisterStepOne;
Share
Improve this question
edited Nov 30, 2018 at 11:52
DarkMukke
2,4891 gold badge24 silver badges32 bronze badges
asked Nov 28, 2018 at 15:31
BradBrad
1333 gold badges5 silver badges13 bronze badges
4
-
Is
RegisterStepOne
used in someForm
? Could you show its parent? What isFormCard
? I can't see it in imports – barbsan Commented Nov 29, 2018 at 6:59 -
Wele to Stack Overflow! I have edited your question with different formatting and edited the html element
<form>
to<form>
as this is flagged by the system for anti spam measures. You should also stick to just the problem, and try not to repeat yourself. – DarkMukke Commented Nov 30, 2018 at 11:40 -
1
@DarkMukke I've also gone ahead and reintroduced the
<form>
tags, but with the correct formatting (Indenting to format it as code). I've also removed some noise, as "Thanks!", "Much Appreciated", which usually detracts from the question at hand. – Blue Commented Nov 30, 2018 at 11:44 - @FrankerZ yes much better, I did introduce a > out of nowhere that I removed. – DarkMukke Commented Nov 30, 2018 at 11:53
2 Answers
Reset to default 3Looking at the console screenshot suggests that <RegisterStepOne />
is a child of a <form>
somewhere higher up the ponent tree.
You are seeing the error because your DOM renders to something like this
<form>
<div>
<form>
<input />
</form>
</div>
</form>
Which is not valid HTML
In this case, you have DOM nesting error.
Cause of dom tree, <form>
in <form>
as follows:
<form>
<form></form>
</form>
If you want serve this, you'll change your form dom tree nesting.
版权声明:本文标题:javascript - Warning: validateDOMNesting(...): <form> cannot appear as a descendant of <form> - Stac 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744052569a2582689.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论