Search code examples
react-final-form

Show errors on Field on load form


I use react-final-form with material-ui and put defaultValue from database which sometimes can be wrong (they where push in the database by a script). Is there a way to display errors, when the component loads ?

<Field
  component={MyComponent}
  defaultValue="my value from database"
  name="name"
/>


Solution

  • You didn't share much code, so I'm not 100% sure what you're attempting to do, but...

    If the field has an error, it will be present on first load.

    Rather than defaultValue, you should be setting the initialValues in the <Form/> component with the values from the database.

    Hope that helps?