user8022517
user8022517

Reputation:

getting values from <Field> onSubmit using React.js and redux.

Hi I am learning Reactjs, redux, and I want to simply print to console.log the username and password for this form.

I have tried console.log(e.target.user.value) but I a getting no results.

here is the handle function. enter image description here

and then the Form and 2 fields. enter image description here

enter image description here

how can I print the value of username and password in the handleSubmit function ?

Upvotes: 0

Views: 89

Answers (1)

Krina Soni
Krina Soni

Reputation: 930

Try Below Code:

handleSubmit = values => {
   console.log('values',values);
   //Here you will get values in values.username & values.password
}

render(){
  const { handleSubmit } = this.props;
  return(
     <form onSubmit={handleSubmit(this.handleSubmit)}>
        <div className="form-inputs">
         <Field type="text" label="Name" name="username" data-fieldname="username" 
           component={bootstrapFormField} placeholder="Username" />
         <Field type="password" label="Password" name="password" data- 
           fieldname="password" component={bootstrapFormField} 
           placeholder="Password" />
        </div>
        <div className="form-actions text-right">
          <button type="submit" className="btn btn-submit green">
                Sign In
          </button>
        </div>
    </form>
   )
}

Upvotes: 1

Related Questions