How to show Error Message When someone leave Empty Fields
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
I want to add Error Message in my form. Currently i am working on ReactJs and i am absolute new new to reactJs i used ant-design form and form is already validated but did not show error message in text when someone leave empty fields . Please help me out because i am really stuck . Thank You
Form Code
import React from 'react';
import styled from 'styled-components';
import 'antd/dist/antd.css';
import Input from 'antd/lib/input';
const FormCard = styled.div`
max-width: 100%;
overflow: hidden;
transition: all 0.3s cubic-bezier(0.41, 0.094, 0.54, 0.07) 0s;
margin-top: 30px;
`;
const FormItem = styled.div`
font-family: 'Chinese Quote', -apple-system, BlinkMacSystemFont, 'Segoe UI',
'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'Helvetica Neue',
Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji',
'Segoe UI Symbol';
font-size: 14px;
font-variant: tabular-nums;
color: rgba(0, 0, 0, 0.65);
-webkit-box-sizing: border-box;
box-sizing: border-box;
margin: 0;
padding: 0;
list-style: none;
margin-bottom: 18px;
vertical-align: top;
`;
class RegisterStepOne extends React.Component {
render() {
const { getFieldDecorator } = this.props;
return (
<div>
<FormCard>
<FormItem label="E-mail">
{getFieldDecorator('firstName', {
rules: [
{
required: true,
message: 'Please input your First name!',
whitespace: true,
},
],
})(<Input placeholder="First name" />)}
</FormItem>
<FormItem label="E-mail">
{getFieldDecorator('lastName', {
rules: [
{
required: true,
message: 'Please input your Last name!',
whitespace: true,
},
],
})(<Input placeholder="Last name" />)}
</FormItem>
<FormItem label="E-mail">
{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>
</FormCard>
</div>
);
}
}
export default RegisterStepOne;
javascript reactjs ecmascript-6 antd ant-design-pro
add a comment |
I want to add Error Message in my form. Currently i am working on ReactJs and i am absolute new new to reactJs i used ant-design form and form is already validated but did not show error message in text when someone leave empty fields . Please help me out because i am really stuck . Thank You
Form Code
import React from 'react';
import styled from 'styled-components';
import 'antd/dist/antd.css';
import Input from 'antd/lib/input';
const FormCard = styled.div`
max-width: 100%;
overflow: hidden;
transition: all 0.3s cubic-bezier(0.41, 0.094, 0.54, 0.07) 0s;
margin-top: 30px;
`;
const FormItem = styled.div`
font-family: 'Chinese Quote', -apple-system, BlinkMacSystemFont, 'Segoe UI',
'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'Helvetica Neue',
Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji',
'Segoe UI Symbol';
font-size: 14px;
font-variant: tabular-nums;
color: rgba(0, 0, 0, 0.65);
-webkit-box-sizing: border-box;
box-sizing: border-box;
margin: 0;
padding: 0;
list-style: none;
margin-bottom: 18px;
vertical-align: top;
`;
class RegisterStepOne extends React.Component {
render() {
const { getFieldDecorator } = this.props;
return (
<div>
<FormCard>
<FormItem label="E-mail">
{getFieldDecorator('firstName', {
rules: [
{
required: true,
message: 'Please input your First name!',
whitespace: true,
},
],
})(<Input placeholder="First name" />)}
</FormItem>
<FormItem label="E-mail">
{getFieldDecorator('lastName', {
rules: [
{
required: true,
message: 'Please input your Last name!',
whitespace: true,
},
],
})(<Input placeholder="Last name" />)}
</FormItem>
<FormItem label="E-mail">
{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>
</FormCard>
</div>
);
}
}
export default RegisterStepOne;
javascript reactjs ecmascript-6 antd ant-design-pro
add a comment |
I want to add Error Message in my form. Currently i am working on ReactJs and i am absolute new new to reactJs i used ant-design form and form is already validated but did not show error message in text when someone leave empty fields . Please help me out because i am really stuck . Thank You
Form Code
import React from 'react';
import styled from 'styled-components';
import 'antd/dist/antd.css';
import Input from 'antd/lib/input';
const FormCard = styled.div`
max-width: 100%;
overflow: hidden;
transition: all 0.3s cubic-bezier(0.41, 0.094, 0.54, 0.07) 0s;
margin-top: 30px;
`;
const FormItem = styled.div`
font-family: 'Chinese Quote', -apple-system, BlinkMacSystemFont, 'Segoe UI',
'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'Helvetica Neue',
Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji',
'Segoe UI Symbol';
font-size: 14px;
font-variant: tabular-nums;
color: rgba(0, 0, 0, 0.65);
-webkit-box-sizing: border-box;
box-sizing: border-box;
margin: 0;
padding: 0;
list-style: none;
margin-bottom: 18px;
vertical-align: top;
`;
class RegisterStepOne extends React.Component {
render() {
const { getFieldDecorator } = this.props;
return (
<div>
<FormCard>
<FormItem label="E-mail">
{getFieldDecorator('firstName', {
rules: [
{
required: true,
message: 'Please input your First name!',
whitespace: true,
},
],
})(<Input placeholder="First name" />)}
</FormItem>
<FormItem label="E-mail">
{getFieldDecorator('lastName', {
rules: [
{
required: true,
message: 'Please input your Last name!',
whitespace: true,
},
],
})(<Input placeholder="Last name" />)}
</FormItem>
<FormItem label="E-mail">
{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>
</FormCard>
</div>
);
}
}
export default RegisterStepOne;
javascript reactjs ecmascript-6 antd ant-design-pro
I want to add Error Message in my form. Currently i am working on ReactJs and i am absolute new new to reactJs i used ant-design form and form is already validated but did not show error message in text when someone leave empty fields . Please help me out because i am really stuck . Thank You
Form Code
import React from 'react';
import styled from 'styled-components';
import 'antd/dist/antd.css';
import Input from 'antd/lib/input';
const FormCard = styled.div`
max-width: 100%;
overflow: hidden;
transition: all 0.3s cubic-bezier(0.41, 0.094, 0.54, 0.07) 0s;
margin-top: 30px;
`;
const FormItem = styled.div`
font-family: 'Chinese Quote', -apple-system, BlinkMacSystemFont, 'Segoe UI',
'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'Helvetica Neue',
Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji',
'Segoe UI Symbol';
font-size: 14px;
font-variant: tabular-nums;
color: rgba(0, 0, 0, 0.65);
-webkit-box-sizing: border-box;
box-sizing: border-box;
margin: 0;
padding: 0;
list-style: none;
margin-bottom: 18px;
vertical-align: top;
`;
class RegisterStepOne extends React.Component {
render() {
const { getFieldDecorator } = this.props;
return (
<div>
<FormCard>
<FormItem label="E-mail">
{getFieldDecorator('firstName', {
rules: [
{
required: true,
message: 'Please input your First name!',
whitespace: true,
},
],
})(<Input placeholder="First name" />)}
</FormItem>
<FormItem label="E-mail">
{getFieldDecorator('lastName', {
rules: [
{
required: true,
message: 'Please input your Last name!',
whitespace: true,
},
],
})(<Input placeholder="Last name" />)}
</FormItem>
<FormItem label="E-mail">
{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>
</FormCard>
</div>
);
}
}
export default RegisterStepOne;
javascript reactjs ecmascript-6 antd ant-design-pro
javascript reactjs ecmascript-6 antd ant-design-pro
asked Nov 24 '18 at 10:08
Jonas SchemeJonas Scheme
12
12
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
I used your code and applied the antd original demo.
you might have missed a thing or two, check it out :
https://codepen.io/fawzisf/pen/RqyQVy
const { Form, Icon, Input, Button, Checkbox } = antd;
const FormItem = Form.Item;
class NormalLoginForm extends React.Component {
handleSubmit = (e) => {
e.preventDefault();
this.props.form.validateFields((err, values) => {
if (!err) {
console.log('Received values of form: ', values);
}
});
}
render() {
const { getFieldDecorator } = this.props.form;
return (
<Form onSubmit={this.handleSubmit} className="login-form">
<FormItem label="E-mail">
{getFieldDecorator('firstName', {
rules: [
{
required: true,
message: 'Please input your First name!',
whitespace: true,
},
],
})(<Input placeholder="First name" />)}
</FormItem>
<FormItem label="E-mail">
{getFieldDecorator('lastName', {
rules: [
{
required: true,
message: 'Please input your Last name!',
whitespace: true,
},
],
})(<Input placeholder="Last name" />)}
</FormItem>
<FormItem label="E-mail">
{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>
<FormItem>
{getFieldDecorator('remember', {
valuePropName: 'checked',
initialValue: true,
})(
<Checkbox>Remember me</Checkbox>
)}
<a className="login-form-forgot" href="">Forgot password</a>
<Button type="primary" htmlType="submit" className="login-form-button">
Log in
</Button>
Or <a href="">register now!</a>
</FormItem>
</Form>
);
}
}
const WrappedNormalLoginForm = Form.create()(NormalLoginForm);
ReactDOM.render(<WrappedNormalLoginForm />, mountNode);
Thank You for your help
– Jonas Scheme
Nov 24 '18 at 12:37
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53457101%2fhow-to-show-error-message-when-someone-leave-empty-fields%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I used your code and applied the antd original demo.
you might have missed a thing or two, check it out :
https://codepen.io/fawzisf/pen/RqyQVy
const { Form, Icon, Input, Button, Checkbox } = antd;
const FormItem = Form.Item;
class NormalLoginForm extends React.Component {
handleSubmit = (e) => {
e.preventDefault();
this.props.form.validateFields((err, values) => {
if (!err) {
console.log('Received values of form: ', values);
}
});
}
render() {
const { getFieldDecorator } = this.props.form;
return (
<Form onSubmit={this.handleSubmit} className="login-form">
<FormItem label="E-mail">
{getFieldDecorator('firstName', {
rules: [
{
required: true,
message: 'Please input your First name!',
whitespace: true,
},
],
})(<Input placeholder="First name" />)}
</FormItem>
<FormItem label="E-mail">
{getFieldDecorator('lastName', {
rules: [
{
required: true,
message: 'Please input your Last name!',
whitespace: true,
},
],
})(<Input placeholder="Last name" />)}
</FormItem>
<FormItem label="E-mail">
{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>
<FormItem>
{getFieldDecorator('remember', {
valuePropName: 'checked',
initialValue: true,
})(
<Checkbox>Remember me</Checkbox>
)}
<a className="login-form-forgot" href="">Forgot password</a>
<Button type="primary" htmlType="submit" className="login-form-button">
Log in
</Button>
Or <a href="">register now!</a>
</FormItem>
</Form>
);
}
}
const WrappedNormalLoginForm = Form.create()(NormalLoginForm);
ReactDOM.render(<WrappedNormalLoginForm />, mountNode);
Thank You for your help
– Jonas Scheme
Nov 24 '18 at 12:37
add a comment |
I used your code and applied the antd original demo.
you might have missed a thing or two, check it out :
https://codepen.io/fawzisf/pen/RqyQVy
const { Form, Icon, Input, Button, Checkbox } = antd;
const FormItem = Form.Item;
class NormalLoginForm extends React.Component {
handleSubmit = (e) => {
e.preventDefault();
this.props.form.validateFields((err, values) => {
if (!err) {
console.log('Received values of form: ', values);
}
});
}
render() {
const { getFieldDecorator } = this.props.form;
return (
<Form onSubmit={this.handleSubmit} className="login-form">
<FormItem label="E-mail">
{getFieldDecorator('firstName', {
rules: [
{
required: true,
message: 'Please input your First name!',
whitespace: true,
},
],
})(<Input placeholder="First name" />)}
</FormItem>
<FormItem label="E-mail">
{getFieldDecorator('lastName', {
rules: [
{
required: true,
message: 'Please input your Last name!',
whitespace: true,
},
],
})(<Input placeholder="Last name" />)}
</FormItem>
<FormItem label="E-mail">
{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>
<FormItem>
{getFieldDecorator('remember', {
valuePropName: 'checked',
initialValue: true,
})(
<Checkbox>Remember me</Checkbox>
)}
<a className="login-form-forgot" href="">Forgot password</a>
<Button type="primary" htmlType="submit" className="login-form-button">
Log in
</Button>
Or <a href="">register now!</a>
</FormItem>
</Form>
);
}
}
const WrappedNormalLoginForm = Form.create()(NormalLoginForm);
ReactDOM.render(<WrappedNormalLoginForm />, mountNode);
Thank You for your help
– Jonas Scheme
Nov 24 '18 at 12:37
add a comment |
I used your code and applied the antd original demo.
you might have missed a thing or two, check it out :
https://codepen.io/fawzisf/pen/RqyQVy
const { Form, Icon, Input, Button, Checkbox } = antd;
const FormItem = Form.Item;
class NormalLoginForm extends React.Component {
handleSubmit = (e) => {
e.preventDefault();
this.props.form.validateFields((err, values) => {
if (!err) {
console.log('Received values of form: ', values);
}
});
}
render() {
const { getFieldDecorator } = this.props.form;
return (
<Form onSubmit={this.handleSubmit} className="login-form">
<FormItem label="E-mail">
{getFieldDecorator('firstName', {
rules: [
{
required: true,
message: 'Please input your First name!',
whitespace: true,
},
],
})(<Input placeholder="First name" />)}
</FormItem>
<FormItem label="E-mail">
{getFieldDecorator('lastName', {
rules: [
{
required: true,
message: 'Please input your Last name!',
whitespace: true,
},
],
})(<Input placeholder="Last name" />)}
</FormItem>
<FormItem label="E-mail">
{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>
<FormItem>
{getFieldDecorator('remember', {
valuePropName: 'checked',
initialValue: true,
})(
<Checkbox>Remember me</Checkbox>
)}
<a className="login-form-forgot" href="">Forgot password</a>
<Button type="primary" htmlType="submit" className="login-form-button">
Log in
</Button>
Or <a href="">register now!</a>
</FormItem>
</Form>
);
}
}
const WrappedNormalLoginForm = Form.create()(NormalLoginForm);
ReactDOM.render(<WrappedNormalLoginForm />, mountNode);
I used your code and applied the antd original demo.
you might have missed a thing or two, check it out :
https://codepen.io/fawzisf/pen/RqyQVy
const { Form, Icon, Input, Button, Checkbox } = antd;
const FormItem = Form.Item;
class NormalLoginForm extends React.Component {
handleSubmit = (e) => {
e.preventDefault();
this.props.form.validateFields((err, values) => {
if (!err) {
console.log('Received values of form: ', values);
}
});
}
render() {
const { getFieldDecorator } = this.props.form;
return (
<Form onSubmit={this.handleSubmit} className="login-form">
<FormItem label="E-mail">
{getFieldDecorator('firstName', {
rules: [
{
required: true,
message: 'Please input your First name!',
whitespace: true,
},
],
})(<Input placeholder="First name" />)}
</FormItem>
<FormItem label="E-mail">
{getFieldDecorator('lastName', {
rules: [
{
required: true,
message: 'Please input your Last name!',
whitespace: true,
},
],
})(<Input placeholder="Last name" />)}
</FormItem>
<FormItem label="E-mail">
{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>
<FormItem>
{getFieldDecorator('remember', {
valuePropName: 'checked',
initialValue: true,
})(
<Checkbox>Remember me</Checkbox>
)}
<a className="login-form-forgot" href="">Forgot password</a>
<Button type="primary" htmlType="submit" className="login-form-button">
Log in
</Button>
Or <a href="">register now!</a>
</FormItem>
</Form>
);
}
}
const WrappedNormalLoginForm = Form.create()(NormalLoginForm);
ReactDOM.render(<WrappedNormalLoginForm />, mountNode);
const { Form, Icon, Input, Button, Checkbox } = antd;
const FormItem = Form.Item;
class NormalLoginForm extends React.Component {
handleSubmit = (e) => {
e.preventDefault();
this.props.form.validateFields((err, values) => {
if (!err) {
console.log('Received values of form: ', values);
}
});
}
render() {
const { getFieldDecorator } = this.props.form;
return (
<Form onSubmit={this.handleSubmit} className="login-form">
<FormItem label="E-mail">
{getFieldDecorator('firstName', {
rules: [
{
required: true,
message: 'Please input your First name!',
whitespace: true,
},
],
})(<Input placeholder="First name" />)}
</FormItem>
<FormItem label="E-mail">
{getFieldDecorator('lastName', {
rules: [
{
required: true,
message: 'Please input your Last name!',
whitespace: true,
},
],
})(<Input placeholder="Last name" />)}
</FormItem>
<FormItem label="E-mail">
{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>
<FormItem>
{getFieldDecorator('remember', {
valuePropName: 'checked',
initialValue: true,
})(
<Checkbox>Remember me</Checkbox>
)}
<a className="login-form-forgot" href="">Forgot password</a>
<Button type="primary" htmlType="submit" className="login-form-button">
Log in
</Button>
Or <a href="">register now!</a>
</FormItem>
</Form>
);
}
}
const WrappedNormalLoginForm = Form.create()(NormalLoginForm);
ReactDOM.render(<WrappedNormalLoginForm />, mountNode);
const { Form, Icon, Input, Button, Checkbox } = antd;
const FormItem = Form.Item;
class NormalLoginForm extends React.Component {
handleSubmit = (e) => {
e.preventDefault();
this.props.form.validateFields((err, values) => {
if (!err) {
console.log('Received values of form: ', values);
}
});
}
render() {
const { getFieldDecorator } = this.props.form;
return (
<Form onSubmit={this.handleSubmit} className="login-form">
<FormItem label="E-mail">
{getFieldDecorator('firstName', {
rules: [
{
required: true,
message: 'Please input your First name!',
whitespace: true,
},
],
})(<Input placeholder="First name" />)}
</FormItem>
<FormItem label="E-mail">
{getFieldDecorator('lastName', {
rules: [
{
required: true,
message: 'Please input your Last name!',
whitespace: true,
},
],
})(<Input placeholder="Last name" />)}
</FormItem>
<FormItem label="E-mail">
{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>
<FormItem>
{getFieldDecorator('remember', {
valuePropName: 'checked',
initialValue: true,
})(
<Checkbox>Remember me</Checkbox>
)}
<a className="login-form-forgot" href="">Forgot password</a>
<Button type="primary" htmlType="submit" className="login-form-button">
Log in
</Button>
Or <a href="">register now!</a>
</FormItem>
</Form>
);
}
}
const WrappedNormalLoginForm = Form.create()(NormalLoginForm);
ReactDOM.render(<WrappedNormalLoginForm />, mountNode);
answered Nov 24 '18 at 10:59
FawziFawzi
267110
267110
Thank You for your help
– Jonas Scheme
Nov 24 '18 at 12:37
add a comment |
Thank You for your help
– Jonas Scheme
Nov 24 '18 at 12:37
Thank You for your help
– Jonas Scheme
Nov 24 '18 at 12:37
Thank You for your help
– Jonas Scheme
Nov 24 '18 at 12:37
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53457101%2fhow-to-show-error-message-when-someone-leave-empty-fields%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown