How to show multiple error line which using Formik and yup?
Asked Answered
C

1

6

I have tried to write the multiple error line which is using formik and yup validation. After use this.createError() it turns error message as string not array as {errors: '4 errors occurred'}.

example code that I did:

const messages = [
  { key: "length", message: "should have  password at least 8 characters" },
  { key: "notRepeat", message: "should not repeat old password" }
];

this.createError({
  path: `${this.path}`,
  message: messages,
  errors: messages
});

What I need to be is errors that I need it to return as messages([]) Constance then I show a list of error thru UI.

Any comments or suggestions to solve this?

Thank you.

Cyrilcyrill answered 9/3, 2020 at 4:31 Comment(0)
M
0

Try this:

const errors = messages.map((msg) => ({
  path: this.path,
  message: msg.message,
}));

this.createError(errors);
Moline answered 10/3, 2023 at 14:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.