I'm struggling to figure out how we're supposed to handle submitting a form in React. First time user, failed hard so far.
The data in the form is always empty meaning the json is also empty.
As far as I can tell from all the examples I've read this should be working.
My component is a simple registration component:
import * as React from 'react';
import { PropsType } from './Routes';
import { Form, Col, FormGroup, ControlLabel, FormControl, Button } from 'react-bootstrap';
export default class Register extends React.Component<PropsType, any> {
public constructor(props, context) {
super(props, context);
this.handleSubmit = this.handleSubmit.bind(this);
}
public render() {
return <Form horizontal onSubmit={this.handleSubmit} id={'reg-form'}>
<FormGroup controlId="formHEmail">
<Col componentClass={ControlLabel} sm={2}>
Email
</Col>
<Col sm={10}>
<FormControl type="email" placeholder="Email" />
</Col>
</FormGroup>
<FormGroup controlId="formPassword">
<Col componentClass={ControlLabel} sm={2}>
Password
</Col>
<Col sm={10}>
<FormControl type="password" placeholder="Password" />
</Col>
</FormGroup>
<FormGroup controlId="formConfirmPassword">
<Col componentClass={ControlLabel} sm={2}>
Confirm Password
</Col>
<Col sm={10}>
<FormControl type="password" placeholder="Confirm Password" />
</Col>
</FormGroup>
<FormGroup>
<Col smOffset={2} sm={10}>
<Button type="submit">Create Account</Button>
</Col>
</FormGroup>
</Form>;
}
public handleSubmit(e) {
e.preventDefault();
console.log('Register.POST');
console.log('TARGET IS: ' + e.target);
const data = new FormData(e.target);
console.log(data);
const json = JSON.stringify(data);
console.log(json);
fetch('/api/account/register', {
method: 'POST',
headers: {
'Access-Control-Allow-Origin': '*',
'Content-Type': 'application/json',
'Accept': 'application/json',
},
body: json,
}).then(res => {
console.log(res);
});
}
}
How can I get the values from the form into json data?
I have this bit of code: const data = { x: "Target" } let bar = () => { console.log(this.x) } let final = bar.bind(data); final(); This code returns undefined. Here is the same code, but ...
I have this bit of code: const data = { x: "Target" } let bar = () => { console.log(this.x) } let final = bar.bind(data); final(); This code returns undefined. Here is the same code, but ...
I'm building a filter sidebar for my site, I want to be able to open and close the filter lists by pressing a btn. jQuery('.parent > .children').parent().click(function() { jQuery(this)....
I'm building a filter sidebar for my site, I want to be able to open and close the filter lists by pressing a btn. jQuery('.parent > .children').parent().click(function() { jQuery(this)....
Is it possible to create a coverage report with jest for files that satisfy a wildcard path? After the latest release of jest, I can finally create coverage for files specified in the "...
Is it possible to create a coverage report with jest for files that satisfy a wildcard path? After the latest release of jest, I can finally create coverage for files specified in the "...
I have cookie value stored in following format {stamp:'HMzWoJn8V4ZkdRN1DduMHLhS3dKiDDr6VoXCjjeuDMO2w6V+n2CcOg==',necessary:true,preferences:true,statistics:true,marketing:false,ver:1} and i need ...
I have cookie value stored in following format {stamp:'HMzWoJn8V4ZkdRN1DduMHLhS3dKiDDr6VoXCjjeuDMO2w6V+n2CcOg==',necessary:true,preferences:true,statistics:true,marketing:false,ver:1} and i need ...