Please find problem in my ReactJs Form, It Not working
I am working on Wizard form in reactjs, Form is working fine but sometime when i click on next button data is not coming to my console when i click on previous button and submit data again it coming to the console but in first attempt data is not coming to my console and it give me null message please check it out and help me . Thanks
Form Code
I used this form from ( Ant-design )
import React from 'react';
import styled from 'styled-components';
import 'antd/dist/antd.css';
import './FirstStep.css';
import { Form, Input } from 'antd';
const FormItem = Form.Item;
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;
`;
class RegisterStepOne extends React.Component {
handleSubmit = e => {
e.preventDefault();
this.props.form.validateFields((err, values) => {
if (!err) {
console.log('Received values of form: ', values.toString());
}
});
};
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;
javascript reactjs react-native ecmascript-6 react-redux
add a comment |
I am working on Wizard form in reactjs, Form is working fine but sometime when i click on next button data is not coming to my console when i click on previous button and submit data again it coming to the console but in first attempt data is not coming to my console and it give me null message please check it out and help me . Thanks
Form Code
I used this form from ( Ant-design )
import React from 'react';
import styled from 'styled-components';
import 'antd/dist/antd.css';
import './FirstStep.css';
import { Form, Input } from 'antd';
const FormItem = Form.Item;
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;
`;
class RegisterStepOne extends React.Component {
handleSubmit = e => {
e.preventDefault();
this.props.form.validateFields((err, values) => {
if (!err) {
console.log('Received values of form: ', values.toString());
}
});
};
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;
javascript reactjs react-native ecmascript-6 react-redux
can you add code for the Button component as well ?
– Pranay Tripathi
Nov 24 '18 at 13:33
Here i am showing input value ` handleSubmit = e => { e.preventDefault(); this.props.form.validateFieldsAndScroll((err, values) => { if (!err) { this.setState({ user: { ...values } }); console.info(this.state.user);`
– Jonas Scheme
Nov 24 '18 at 13:38
add a comment |
I am working on Wizard form in reactjs, Form is working fine but sometime when i click on next button data is not coming to my console when i click on previous button and submit data again it coming to the console but in first attempt data is not coming to my console and it give me null message please check it out and help me . Thanks
Form Code
I used this form from ( Ant-design )
import React from 'react';
import styled from 'styled-components';
import 'antd/dist/antd.css';
import './FirstStep.css';
import { Form, Input } from 'antd';
const FormItem = Form.Item;
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;
`;
class RegisterStepOne extends React.Component {
handleSubmit = e => {
e.preventDefault();
this.props.form.validateFields((err, values) => {
if (!err) {
console.log('Received values of form: ', values.toString());
}
});
};
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;
javascript reactjs react-native ecmascript-6 react-redux
I am working on Wizard form in reactjs, Form is working fine but sometime when i click on next button data is not coming to my console when i click on previous button and submit data again it coming to the console but in first attempt data is not coming to my console and it give me null message please check it out and help me . Thanks
Form Code
I used this form from ( Ant-design )
import React from 'react';
import styled from 'styled-components';
import 'antd/dist/antd.css';
import './FirstStep.css';
import { Form, Input } from 'antd';
const FormItem = Form.Item;
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;
`;
class RegisterStepOne extends React.Component {
handleSubmit = e => {
e.preventDefault();
this.props.form.validateFields((err, values) => {
if (!err) {
console.log('Received values of form: ', values.toString());
}
});
};
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;
javascript reactjs react-native ecmascript-6 react-redux
javascript reactjs react-native ecmascript-6 react-redux
asked Nov 24 '18 at 12:54
Jonas SchemeJonas Scheme
12
12
can you add code for the Button component as well ?
– Pranay Tripathi
Nov 24 '18 at 13:33
Here i am showing input value ` handleSubmit = e => { e.preventDefault(); this.props.form.validateFieldsAndScroll((err, values) => { if (!err) { this.setState({ user: { ...values } }); console.info(this.state.user);`
– Jonas Scheme
Nov 24 '18 at 13:38
add a comment |
can you add code for the Button component as well ?
– Pranay Tripathi
Nov 24 '18 at 13:33
Here i am showing input value ` handleSubmit = e => { e.preventDefault(); this.props.form.validateFieldsAndScroll((err, values) => { if (!err) { this.setState({ user: { ...values } }); console.info(this.state.user);`
– Jonas Scheme
Nov 24 '18 at 13:38
can you add code for the Button component as well ?
– Pranay Tripathi
Nov 24 '18 at 13:33
can you add code for the Button component as well ?
– Pranay Tripathi
Nov 24 '18 at 13:33
Here i am showing input value ` handleSubmit = e => { e.preventDefault(); this.props.form.validateFieldsAndScroll((err, values) => { if (!err) { this.setState({ user: { ...values } }); console.info(this.state.user);`
– Jonas Scheme
Nov 24 '18 at 13:38
Here i am showing input value ` handleSubmit = e => { e.preventDefault(); this.props.form.validateFieldsAndScroll((err, values) => { if (!err) { this.setState({ user: { ...values } }); console.info(this.state.user);`
– Jonas Scheme
Nov 24 '18 at 13:38
add a comment |
1 Answer
1
active
oldest
votes
Looking at your comment above, it looks as though you are logging this.state
to the console immediately after calling this.setState
. You can't reliably check the value of this.state
immediately after calling this.setState
. this.setState
is asynchronous and you will get the the old state value. If you want to log the value after the state update completes, there is a second argument to this.setState
that accepts a callback function to run when the state update complets. For example:
this.setState({ user: { ...values } }, () => console.log(this.state.user));
You can read more about this behavior in the official React documentation on setState here.
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%2f53458363%2fplease-find-problem-in-my-reactjs-form-it-not-working%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
Looking at your comment above, it looks as though you are logging this.state
to the console immediately after calling this.setState
. You can't reliably check the value of this.state
immediately after calling this.setState
. this.setState
is asynchronous and you will get the the old state value. If you want to log the value after the state update completes, there is a second argument to this.setState
that accepts a callback function to run when the state update complets. For example:
this.setState({ user: { ...values } }, () => console.log(this.state.user));
You can read more about this behavior in the official React documentation on setState here.
add a comment |
Looking at your comment above, it looks as though you are logging this.state
to the console immediately after calling this.setState
. You can't reliably check the value of this.state
immediately after calling this.setState
. this.setState
is asynchronous and you will get the the old state value. If you want to log the value after the state update completes, there is a second argument to this.setState
that accepts a callback function to run when the state update complets. For example:
this.setState({ user: { ...values } }, () => console.log(this.state.user));
You can read more about this behavior in the official React documentation on setState here.
add a comment |
Looking at your comment above, it looks as though you are logging this.state
to the console immediately after calling this.setState
. You can't reliably check the value of this.state
immediately after calling this.setState
. this.setState
is asynchronous and you will get the the old state value. If you want to log the value after the state update completes, there is a second argument to this.setState
that accepts a callback function to run when the state update complets. For example:
this.setState({ user: { ...values } }, () => console.log(this.state.user));
You can read more about this behavior in the official React documentation on setState here.
Looking at your comment above, it looks as though you are logging this.state
to the console immediately after calling this.setState
. You can't reliably check the value of this.state
immediately after calling this.setState
. this.setState
is asynchronous and you will get the the old state value. If you want to log the value after the state update completes, there is a second argument to this.setState
that accepts a callback function to run when the state update complets. For example:
this.setState({ user: { ...values } }, () => console.log(this.state.user));
You can read more about this behavior in the official React documentation on setState here.
answered Nov 24 '18 at 16:26
TylerTyler
1,00117
1,00117
add a comment |
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%2f53458363%2fplease-find-problem-in-my-reactjs-form-it-not-working%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
can you add code for the Button component as well ?
– Pranay Tripathi
Nov 24 '18 at 13:33
Here i am showing input value ` handleSubmit = e => { e.preventDefault(); this.props.form.validateFieldsAndScroll((err, values) => { if (!err) { this.setState({ user: { ...values } }); console.info(this.state.user);`
– Jonas Scheme
Nov 24 '18 at 13:38