在普通頁面和模態(tài)上有一些表單字段,我希望模態(tài)按鈕觸發(fā)提交事件。每當我在模態(tài)按鈕上使用提交類型=“提交”時,我都沒有得到任何響應。但如果我在普通頁面按鈕中使用它,它就可以工作。請問這是怎么回事,我不能在模態(tài)中使用它嗎? <Formik initialValues={{ productName: "", productNumber: "", quantity: 1, unitCost: 0, totalCost: 0, customerName: "", customerNumber: "", amount: "", }} onSubmit={(data, { setSubmitting }) => { setSubmitting(true); setTimeout(() => { console.log(data); alert(JSON.stringify(data, null, 2)); setSubmitting(false); }, 2000); }} > {({ values, handleBlur, handleChange, setFieldValue, isSubmitting, }) => ( <Form> <Box> <Grid templateColumns="repeat(2, 1fr)" gap={5}> <Box> <FormLabel>Product Name:</FormLabel> <Field as={Input} name="productName" type="text" placeholder="Product Name:" /> </Box> <Box> <FormLabel>Product Number:</FormLabel> <Field as={Input} name="productNumber" type="number" placeholder="Product Number:" /> </Box> <Box> <FormLabel>Quantity:</FormLabel> <Field as={Input} name="quantity" type="number" value={values.quantity} onChange={handleChange} onBlur={handleBlur} placeholder="Quantity:" /> </Box> <Box> <FormLabel>Unit Cost:(in Naira)</FormLabel> <Field as={Input} name="unitCost" type="number" value={values.unitCost} onChange={handleChange} onBlur={handleBlur} placeholder="Unit Cost:" /> </Box>
Formik 表單未從模態(tài)組件提交
翻翻過去那場雪
2023-09-07 16:47:52