Kozea / formol

An opinionated react form framework.
MIT License
189 stars 17 forks source link

Reset this.state.modified on form submit #74

Closed notAro14 closed 3 years ago

notAro14 commented 3 years ago

Submiting did not make this.state.modified resetting to false again.

Issue

For example, when passing Prompt component (react-router-dom) like so

const MyForm = () => {
  const history = useHistory()

  const submitHandler = () => {
    const success = doSomethingWithFormItems()
    success && history.push('/somewhere/else')
  }

  return (
    <Formol onSubmit={submitHandler} extra={(state) => (<Prompt when={state.modified} />)}
      {/* ... */}
    </Formol>)
}

It will prompt the user a warning message to confirm the redirection after form submitting. This hangs the redirection waiting for the user confirmation.

But the confirmation is implicit as soon as he clicks the submit button. Therefore there is no need to let the form in a modified state when submiting was successful.

coveralls commented 3 years ago

Pull Request Test Coverage Report for Build 458


Totals Coverage Status
Change from base Build 438: 0.0%
Covered Lines: 735
Relevant Lines: 735

💛 - Coveralls
notAro14 commented 3 years ago

Poke @cmigazzi @gentooboontoo