react-final-form: Form can be submitted even with validation errors

Hey 😃

Are you submitting a bug report or a feature request

Bug report

What is the current behavior

Even with validation errors, I am able to submit a non-valid form if not all fields are rendered.

What is the expected behavior

I expect that I will be not able to submit a non-valid form that has validation errors.

How to reproduce the issue

I took Synchronous Record-Level Validation example and slightly modified it - removed two fields and added console.log with validation errors.

Here is a codesandbox demo - https://codesandbox.io/s/53xrn6v86p

Try to submit an empty form and you will have 3 validation errors. Now, fill in the only field in the form and you’ll still have 2 validation errors. Even though you have errors left, you will be able to submit the form.

Screen Shot

screen shot 2017-11-28 at 00 43 22


This bug also exists in redux-form and was mentioned in issues multiple times. 😢 Maybe it’ll be fixed in the final-form (the title sounds awesome) 🎉

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 1
  • Comments: 21 (13 by maintainers)

Most upvoted comments

The valid/invalid flags are currently based solely on registered fields.

Having thought about this for 24 hours, I think @VladShcherbin might be right. Non-registered field errors should also affect valid/invalid flags and halt submission.

@erikras extra functionality + reduced bundle size 🙂 Maybe you have to reconsider your

I plan on being a little more willing to say, “No, I will not implement your specific feature,” with this library, to minimize its complexity and surface area.

You can add “If it reduces bundle size, it will have a bigger change of being implemented” 😂

LOL, this change actually reduced the size of the bundle.

Published fix in final-form@1.1.0.

Yes. Injecting errors, like we do values into the form render function makes sense.

Published actual fix in final-form v1.2.1.

@erikras I’ve been waiting for this fix for so long, after I found this in redux-form the first thing I check in forms packages is this one.

Thank you ❤️

Having thought about this for a few hours, it seems like you could accomplish what you want with this:

const validate = values => {
  const errors = {}
  // do validation
  return errors
}

const onSubmit = async values => {
  const errors = validate(values)
  if(Object.keys(errors).length) {
    return errors
  }
  // actually submit
  ajax.post('/blahblah', values)
}

You could reuse your record-level validation function to return submission errors, thus halting the submit.

Reasonable? Unreasonable?