提问人:BinaryPhantom 提问时间:11/6/2023 更新时间:11/6/2023 访问量:9
React Formik 问题:上传图像后无法编辑文本字段(错误 500 内部服务器错误)
React Formik Issue: Unable to Edit Text Fields After Uploading an Image (Error 500 Internal Server Error)
问:
我在使用 Formik 处理 React 表单时遇到了一个问题。该表单包括文本字段和图像字段。问题如下:
When there is no image uploaded, I can edit the text fields and successfully save the changes.
However, once I upload an image, I'm unable to edit the text fields. The changes are not saved, and I receive a 500 Internal Server Error in my application.
Important Note: This problem occurs only when I send requests through the interface of my application. If I use Postman to send requests, everything works correctly.
The only way to be able to edit the text fields again is by modifying the image along with the text field and then saving the changes, or by deleting the image from Postman and then attempting to edit the text fields.
下面,我包括我的相关代码的片段:
const initialValues = {
project_name: project?.project_name,
logo: project?.logo,
description: project?.description,
start_date: project?.start_date,
due_date: project?.due_date,
email_notification: true,
phone_notification: false,
notification: true,
} as InitialValuesProps;
const formik = useFormik({
initialValues: initialValues,
validationSchema: Yup.object({
project_name: Yup.string()
.required("Project name is required ")
.min(10, "Min 10 characters"),
description: Yup string()
.required("Description is required")
.min(10, "Min 10 characters"),
start_date: Yup.string().required("Start date is required"),
due_date: Yup.string().required("Due date is required"),
email_notification: Yup boolean(),
phone_notification: Yup boolean(),
notification: Yup.boolean(),
}),
onSubmit: async (values) => {
console.log(values);
if (formik.isValid) {
try {
if(project?.id){
await editProject(project.id.toString(), values);
}
} catch (error) {
console.log(error);
}
}
},
});
我正在寻找一种解决方案,无论是否上传图像,都可以毫无问题地编辑文本字段。
答: 暂无答案
评论