JavaScript React Form Submission - Fields Always Empty react form submission tutorial,react form submission canceled not connected,

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?

Answer:1

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 ...

  1. javascript binding arrow functions
  2. javascript arrow binding

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)....

  1. side menu open close
  2. side menu open close bootstrap
  3. open close sidebar

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 "...

  1. jest code coverage report
  2. jest code coverage not working
  3. jest code coverage html
  4. jest code coverage threshold
  5. jest code coverage typescript
  6. jest code coverage badge
  7. jest code coverage ignore
  8. jest code coverage sonarqube
  9. jest code coverage branches
  10. jest code coverage unknown
  11. jest code coverage setup
  12. jest code coverage include all files
  13. jest code coverage html report
  14. jest code coverage azure devops
  15. jest code coverage percentage
  16. jest code coverage gitlab
  17. jest code coverage vscode
  18. jest code coverage all files
  19. jest code coverage single file
  20. jest code coverage angular

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 ...

  1. read value from dictionary c#
  2. read value from json
  3. read value from appsettings.json
  4. read value from app.config c#
  5. read value from properties file in java
  6. read value from file bash
  7. read value from cell vba
  8. read value from json string in java
  9. read value from dictionary python
  10. read value from web.config c#
  11. read value from file c++
  12. read value from appsettings.json .net core
  13. read value from file python
  14. read value from datatable c#
  15. read value from jobject c#
  16. read value from dataframe
  17. read value from console in java
  18. read value from json file java
  19. read value from application.properties
  20. read value from console in c#