javascript - React onSubmit event not working -


when hit enter on form, not trigger onsubmit event. there no errors. other event, onblur, dispatch. logform function console.log json string of form's fields, have not yet gotten far. trying trigger onsubmit event on form. or explanation appreciated. here's code:

import react 'react'  export default function signupform() {   return (     <form onsubmit={logform}>       <div classname="form-group">         <label>           name:           <input onblur={logupdate} classname="form-control"            type="text" placeholder="username"/>         </label>       </div>       <div classname="form-group">         <label>           email:           <input onblur={logupdate} classname="form-control"            type="text" placeholder="johndoe@example.com"/>         </label>       </div>       <div classname="form-group">         <label>           password:           <input onblur={logupdate} classname="form-control"            type="password" placeholder="password"/>         </label>       </div>       <div classname="form-group">         <label>           confirm password:           <input onblur={logupdate} classname="form-control"            type="password" placeholder="password"/>         </label>       </div>     </form>   ) }  function logform(e) {   e.preventdefault()   const forminfo = new formdata(e.target)   console.log(forminfo) }  function logupdate(e) {   console.log(e.target.value) } 

what can put onkeypressed event on form controls so

onkeypress={this.onkeypressed}

and have function catching onkeypressed

onkeypressed: function (e) {     if (e.key === "enter") {         logform(e);     } } 

if want submit work, add button html section: (credit @tryingtoimprove)

  <div classname="form-group">     <label>       <button classname="btn btn-default" type="submit">submit form</button>     </label>   </div> 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -