V
V
Vitaly the Wise2018-04-02 11:55:07
HTML
Vitaly the Wise, 2018-04-02 11:55:07

How to clear the form correctly so that the message about saving the password does not pop up?

Hello. I'm making a simple form to create a user, and ran into a problem. I write in React. Here is the code:

<form
   id="user-form"
   autoComplete="off"
   noValidate>
     <div className="form-group">
        <div>
          <label>First Name:</label>
        </div>
        <TextField
          name="firstName"
          hintText="First name"
          value={this.state.firstName}
          onChange={this.handleChange} />
       </div>
       <div className="form-group">
         <div>
           <label>Last Name:</label>
         </div>
         <TextField
            name="lastName"
            hintText="Last name"
            value={this.state.lastName}
            onChange={this.handleChange} />
        </div>
        <div className="form-group">
          <div>
            <label>Password:</label>
          </div>
          <TextField
            type="password"
            name="password"
            hintText="Password"
            value={this.state.password}
            onChange={this.handleChange} />
        </div>
        <div className="form-group">
          <div>
            <label>Confirm Password:</label>
          </div>
          <TextField
            type="password"
            name="confirmPassword"
            hintText="Confirm password"
            value={this.state.confirmPassword}
            onChange={this.handleChange} />
        </div>
        <div className="form-footer">
          <button
            className="btn btn-outline-primary"
            type="submit"
            onSubmit={this.handleSubmit}>
            Save
          </button>
          <span className="button-devider"></span>
          <button
            className="btn btn-outline-danger"
            type="reset"
            onClick={this.handleReset}>
            Cancel
          </button>
        </div>
      </form>

When the user wants to cancel the creation, the following event occurs:
handleReset(event) {
    this.setState(this.baseState);
    document.getElementById('affiliate-form').reset();

    // setTimeout(() => this.props.history.push('/users'), 0);
  }

After that, if you leave the page, for example, in Safari, a message about saving the password appears, although the form is empty and the state is too.
Maybe someone faced this problem and knows how to solve it. Thanks

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question