reactjs - 即使未显示,字段仍会发布
问题描述
根据变量的真实性显示字段:
const [paymentCash, setPaymentCash] = useState(null);
...
const onSubmit = async (values) => {
try {
const response = await createGroupService(values);
onSuccess(_getText('notif.msg.group.created.ok'));
} catch (error) {
hideLoader();
}
};
<Formik
initialValues={isUpdate ? updateFormValues : initialValues}
validationSchema={validationSchema}
onSubmit={onSubmit}
>
{(formik) => {
...
<FormikControl
formik={formik}
control="single-select"
label={_getText("billing.model")}
name="billingModel"
options={billingModels}
onChangeEffect={(inputValue) => {
setPaymentCash(inputValue.code == "CASH" ? true : false);
}
}
/>
...
{paymentCash && <FormikControl
control="input"
label={_getText("prix.achat")}
name="purchasePrice"
placeholder={_getText("prix.achat")}
type="number"
/>}
...
<Button text="Submit" type="submit" />
当 paymentCash 为 false 并且提交表单时,我仍然会收到字段 purchasePrice 。那么如何解决呢?
解决方案
推荐阅读
- r - 如何每天运行回归并将系数保存在新数据集中?
- swift - SwiftUI TextField 简单示例不起作用
- typescript - 声明数组,但它显示一个 obj
- c - 错误:指针与空指针的有序比较 [-Werror=extra]
- php - 将内部数组合并为一个
- reactjs - 自定义 Typescript NPM 包不会生成类型
- scala - 不支持的属性值类型:写入 Neptune 时的 java.util.LinkedHashMap
- asp.net - 如何将本地 Webapi 服务和 WCF 服务与我们在 Azure 中的 asp.net 应用程序集成?
- ios - 检测表在 iOS 13 上被取消
- google-analytics - Google Analytics 将主页 URL 替换为“/”为其他内容