Mel*_*Mel 9 firebase reactjs yup google-cloud-firestore formik
我有一个React应用程序,该应用程序将Formik用于表单并将Cloud Firestore用于数据库。
我正在尝试将表单数据保存在Cloud Firestore中。我在控制台或React Inspector工具中没有任何错误,当我按Submit时,我在React Inspection工具中看到按钮变为禁用状态,然后再次启用,但是表单不会清除数据,并且数据确实无法发送到Cloud Firestore。
我的handleSubmit函数具有:
handleSubmit = (formState, { resetForm }) => {
// Now, you're getting form state here!
const payload = {
...formState,
fieldOfResearch: formState.fieldOfResearch.map(t => t.value),
preregisterPlatform: formState.preregisterPlatform.value,
resourceRequests: formState.resourceRequests.map(t => t.value),
resourceOffers: formState.resourceOffers.map(t => t.value),
ethicsIssue: formState.ethicsIssue.map(t => t.value),
disclosureStatus: formState.disclosureStatus.value,
createdAt: firebase.firestore.FieldValue.serverTimestamp()
}
console.log("formvalues", payload);
fsDB
.collection("project")
.add(payload)
.then(docRef => {
console.log("docRef>>>", docRef);
resetForm(initialValues);
})
.catch(error => {
console.error("Error adding document: ", error);
});
};
Run Code Online (Sandbox Code Playgroud)
我的提交按钮有:
<div className="form-group">
<Button
variant="outline-primary"
type="submit"
id="ProjectId"
onClick={handleSubmit}
disabled={!dirty || isSubmitting}
>
Save
</Button>
</div>
Run Code Online (Sandbox Code Playgroud)
表格很长-有39个问题,从Cloud Firestore数据使用情况可以看出,我在读写限制方面无处可寻。我不知道如何衡量表单提交数据的大小,以了解表单数据是否超过Cloud Firestore限制-有没有办法让Firestore告诉您这是否是提交不起作用的原因?
我的控制台日志中查看handleSubmit中的有效负载未运行-所以我认为肯定还有另一个问题-我只是找不到有关问题可能的任何信息。
有没有人遇到长表单无法发布到Cloud Firestore的问题?如果我仅保留前10个问题,则此表单将提交到数据库。
我认为我在firestore的使用限制之内:
下次尝试
因此,我从表格中取出了11-39个问题,并评论了所有的Yup验证。我一次又添加了一个问题,发现该表单可以正常工作并发布到Firestore,直到取消对验证的注释。他们都通过了-没有错误。所以-现在,我想知道是否由Firestore计算了检查它们所花费的时间,这是否可能导致超时?那可能吗?如果是这样,是否有任何方法可以从Firestore得知这是问题所在?我的验证如下。
我尝试批注验证,然后取消批注验证的批注,然后取消批注。批注10,如果我将所有验证从视频向下注释到最后,表单将成功发布到firebase。这些验证中没有错误。我只是无法将它们以及成功发布到数据库中。
<Formik
initialValues={initialValues}
validationSchema={Yup.object().shape({
title: Yup.string().required("Give your proposal a title"),
subtitle: Yup.string().required("Now a subtitle"),
fieldOfResearch: Yup.array().required("What is your field of research?"),
disclosureStatus: Yup.string().nullable().required("Some projects are sensitive. Choose a disclosure setting."),
overview: Yup.string().required("Outline your proposal"),
objective: Yup.string().required("What is your objective?"),
currentThinking: Yup.string().required("Outline the current thinking"),
innovationStatement: Yup.string().required("If this proposal progresses previous research, what are the next steps that are being considered? If it is a paradigm shift, what has prompted it?"),
influence: Yup.string().required("How is this proposal influenced by prevailing opinion?"),
layperson: Yup.string().required("How would you describe this research to someone new to your field?"),
elevator: Yup.string().required("Give it a try."),
// video:
resourcesConfirmation: Yup.string().required("Do you have access to research infrastructure you will need?"),
participantPlan: Yup.string().required("Do you have a plan for how you will recruit participants for this research proposal? If your study does not require participants, then NA will do the job here."),
resourceRequests: Yup.array().required('What sort of resources are you seeking?'),
resourceOffers: Yup.array().required('What sort of resources will you bring to this project?'),
technique: Yup.string().required("Ideally, this answer looks something close to 'Yes, because...' or a 'No, but this team is amazing and will master these techniques in no time, because...'"),
pitfalls: Yup.string().required("If you've tried to look at this objectively, and can't see any pitfalls, then 'Not Applicable' will do here."),
community: Yup.string().required("It can be a good idea to do this. If you do, you'll show sensitivity to the interests of others in your field and may open doors for potential collaborations and translation opportunities."),
samplesize: Yup.string().required("These questions address research quality issues that funders are assessing in considering a proposal."),
methodDescription: Yup.string().required("What approach will you take in this research?"),
qualityControls: Yup.string().required("What controls will you put in place? These should address participants, comparators and any interventions."),
sopAdoption: Yup.string().required("Describe at a summary level, any part of the Statement of Procedures that you have proposed that is noteworthy for reviewers."),
participantNotification: Yup.string().required("Will you notify participants (if there are any) about the outcomes of this research? If so, describe how that will be done."),
preregisterPlatform: Yup.string().nullable().required("Select preregistration intention"),
teamOverview: Yup.string().required("Summarise the collective capabilities and experience of the team making this proposal"),
proposalLead: Yup.string().required("Enter the name of the team leader"),
indigenous: Yup.string().required("Either outline the contribution of indigenous team members or mark this field 'Not Applicable'"),
teamSkillGap: Yup.string().required("Either outline the contribution of indigenous team members or mark this field 'Not Applicable'"),
performanceIndicators: Yup.string().required("Either outline the performance indicators or mark this field 'Not Applicable'"),
timeline: Yup.string().required("Either outline the milestones or mark this field 'Not Applicable'"),
confirmationTeamLead: Yup.boolean().oneOf(
[true],
"Confirmation that you and each team member has reviewed each of the applicable policies is required"
),
outcomeOverview: Yup.string().required("How might your study contribute to knowledge in the field?"),
potentialApplications: Yup.string().required("Do you have any insight into potential applications for this research?"),
potentialResearchAngles: Yup.string().required("Are there any tangential research questions that you think might follow from this study?"),
budget: Yup.string().required("Attach a link to your project budget?"),
ethicsIssue: Yup.array().required("Complete your ethics assessment"),
ethicsManagementPlan: Yup.string().required("Add an ethics management plan, or if there are no issues, complete this field with 'Not Applicable'"),
conflict: Yup.string().required("Are there any conflicts of interest?"),
reproducibility: Yup.string().required("How will you approach reproducibility?"),
})}
Run Code Online (Sandbox Code Playgroud)
我敢打赌,您发送到 firestore 的对象在(11-39 问题)中的某些字段具有undefined或null具有价值。
尝试在发送到 Firestore 之前清除那些未定义的值,因为 Firestore 不会保存undefined值并会抛出错误。
// You can send this to firestore.
const payload = {
a: 1,
b: 'text value',
c: [{ id: 432 }]
}
// You canNOT send this to firestore.
const payload = {
a: 1,
b: undefined,
c: [{ id: 432 }]
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
339 次 |
| 最近记录: |