取消提交表单后恢复表单值

时间:2019-06-05 02:24:34

标签: reactjs react-hooks formik

我正在从事Formik的反应形式。我有提交按钮,它工作正常。当我单击Submit时,将显示一个带有两个按钮的模式,分别是“ Continue eiting”(导航到表单)和“ Submit”(将数据提交到db并返回首页)。 但是,当我单击“继续编辑”时,我填写的值将被清除,并且会返回到先前的状态。

在我单击“继续编辑”之后,有人可以建议如何将这些值保留在表单上吗?

当我单击提交时,将值发送为:true

const setShowPreCampaignModal = (value) => () => {
setModalSettings(prevState => {
  return {
    ...prevState,
    showPreSubmitModal: value,
  }
});

}

//这是单击提交后显示的模式

const renderPreCampaignSubmitModal = () => {
    let firstText = 'Once you submit the campaign, you won't be able to edit .'
    let secondText = 'If you want to keep editing the page, return to the campaign where you can change the details and save the campaign.'

    if (modalSettings.showPreSubmitModal) {
      return (
        <ModalConstructor
          headerInnerHtml="Ready to submit?"
          bodyInnerHtml={renderModalBody({ firstText, secondText })}
          dialogClasses="modal__container"
          footerInnreHtml={renderModalButtons({
            transparentBtnTxt: "Continue Editing",
            blueBtnTxt: "Submit",
            onTransparentClick: setShowPreCampaignModal(false),
            onBlueClick: submitCampaignNewUsingLocalFetch
          })}
          headerClasses="modal__header"
        />
      )
    }
  }

0 个答案:

没有答案