Error: must be a `string` type, but the final value was
See original GitHub issueDescribe the bug
I have a React App which has Formik and use Yup to create the Validation Schema. I recently updated Yup from 0.29.1 -> 0.32.8. I am unaware of any breaking changes since the release page does not contain any change log. The problem is with the react-select component. The initial validation which is triggered by clicking Submit button shows properly “Please select city” (from below codesandbox example). Upon selecting a item from the list it displays error from the validator as "city must be a string
type, but the final value was { "label", "value"}
"
Error seems to be when updating to Yup version higher than 0.29.1.
To Reproduce
Try this sandbox which has Yup version to 0.32.8.
Expected behavior
From the above codesandbox try downgrading to Yup version 0.29.1 which is the expected output. The form has to submit without errors.
Platform (please complete the following information):
- Browser: All browsers
- For libraries versions please refer the above codesandbox
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (2 by maintainers)
@jquense Thanks for the quick response. Instead of recreating the old behavior how do you expect me to write the schema for the react-select input?
see: https://github.com/jquense/yup/blob/master/CHANGELOG.md#breaking-changes-1 plain objects are no longer automatically cast to strings. Judging from your example this is now uncovering a bug you have, assuming you don’t want the value of city to be
'[object Object]'