Object form values is empty when passed to handleSubmit func
See original GitHub issueHi,
I experienced some trouble with redux-form.
So I switch for v6.0.2 instead of v6.2.0 because a friend use this previous version.
Then I have issues with the inputs, wich won’t fill while typing so I make my own renderComponent but speficying the value props as :
const TextField = (props) => {
const { input, meta, ...rest } = props;
return (
<input {...input} {...rest} onChange={input.onChange} value={rest.value}/>
);
};
Now, my inputs fill in but my Object form values is empty in my submit handler. Next the two components in game.
Parent Smart Component
/*
*
* SubscriptionPage
*
*/
import React from 'react';
import { connect } from 'react-redux';
import { Grid, Row, Col } from 'react-flexbox-grid';
import SubscriptionLocalForm from './SubscriptionLocalForm';
import selectSubscriptionPage from './selectors';
import { subscription } from './actions';
import styles from './styles.css';
export class SubscriptionPage extends React.Component { // eslint-disable-line react/prefer-stateless-function
submit = (data) => {
console.log(data);
};
render() {
return (
<Grid>
<Row>
<Col xs={6}>
<h3 className={styles.title}>Inscrivez-vous pour faire des recherches en illimités, recevoir des newsletters...</h3>
</Col>
<Col xs={6}>
<SubscriptionLocalForm onSubmit={this.submit} />
</Col>
</Row>
</Grid>
);
}
}
SubscriptionPage.propTypes = {
submit: React.PropTypes.func,
};
const mapStateToProps = selectSubscriptionPage();
function mapDispatchToProps(dispatch) {
return {
};
}
export default connect(mapStateToProps, mapDispatchToProps)(SubscriptionPage);
Child “Dumb” Component
/**
*
* SubscriptionLocalForm
*
*/
import React from 'react';
import { Field, reduxForm, propTypes } from 'redux-form/immutable';
import styles from './styles.css';
const TextField = (props) => {
const { input, meta, ...rest } = props;
return (
<input {...input} {...rest} onChange={input.onChange} value={rest.value}/>
);
};
const SubscriptionLocalForm = (props) => {
const { handleSubmit } = props;
return (
<form onSubmit={handleSubmit}>
<Field name="email" component={TextField} type="email" placeholder="Email" />
<Field name="password" component={TextField} type="password" placeholder="Mot de passe" />
<Field name="confirmedPassword" component={TextField} type="password" placeholder="Confirmez votre mot de passe" />
<button type="submit">
<span>Essayer gratuitement</span>
<span>Pendant 1 mois</span>
</button>
</form>
);
};
export default reduxForm({
form: 'subscriptionLocal',
validate: (values) => {
const errors = {};
console.log(values);
console.log(values.get('email'));
if (!values.get('email')) {
console.log('email empty');
}
console.log(values.get('password'));
if (!values.get('password')) {
console.log('password empty');
}
return errors;
},
})(SubscriptionLocalForm);
Thanks for your help !
Issue Analytics
- State:
- Created 7 years ago
- Comments:6
Top Results From Across the Web
React redux form handle submit returns empty object
After entering the values when I click Submit button in the handleSubmit() it is showing empty object. Kindly help me to fix this!...
Read more >useForm - handleSubmit - React Hook Form
This function will receive the form data if form validation is successful. Props. Name, Type, Description. SubmitHandler, (data: Object, e?: Event) => void...
Read more >Forms - React
This form has the default HTML form behavior of browsing to a new page when the user submits the form. If you want...
Read more >API Reference - Formik
onSubmit: (values: Values, formikBag: FormikBag) => void | Promise<any>. Your form submission handler. It is passed your forms values and the "FormikBag", which ......
Read more >How to Convert HTML Form Field Values to a JSON Object
function handleSubmit (event) { event.preventDefault(); const data = new FormData(event.target); + const ...
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
Perfect, I couldn’t see what is wrong with your code, good news you were able to find it. Just one thing to mention that I stumbled upon. I see you’re using immutable same as I do, so if at some point you end up importing this by mistake:
instead of:
You will have similar issue where you have value saved in state but it doesn’t get returned back to your input. This is just a heads-up, it happened to me once and I was pulling my hair out trying to find a source of a problem. Now I’m trying to enforce this to be checked by my Eslint library, but I wasn’t successful with that so far.
I find the typo in my code :
Insted of :
the difference is in the name of the reducer “forms” instead of “form”…