[英]Ant design Form "Warning: `callback` is deprecated. Please return a promise instead." Error in custom rules
I made custom rule on form elements.我对表单元素做了自定义规则。 But when i use custom error message with promise its giving that error.
但是当我使用带有承诺的自定义错误消息时,它会给出该错误。 What should i do for fix it ?
我该怎么做才能修复它? My Form elements :
我的表单元素:
That rule is checking PriceMax and PriceMin.该规则是检查 PriceMax 和 PriceMin。 And validate if PriceMax is bigger than PriceMin.
并验证 PriceMax 是否大于 PriceMin。 If Its not it should show me error message.So i used Promise but it making warning in console like : "Warning:
callback
is deprecated. Please return a promise instead."如果不是,它应该向我显示错误消息。所以我使用了 Promise 但它在控制台中发出警告,例如:“警告:
callback
已被弃用。请返回一个承诺。” Error in custom rules"自定义规则错误”
<Form.Item name="PriceMin" label="Minimum fiyat" required>
<Input
type="number"
name="Input"
placeholder="En düşük fiyat"
onChange={(e) => updateForm(e.target.value, "PriceMin")}
/>
</Form.Item>
<Form.Item
name="PriceMax"
label="Maximum fiyat"
dependencies={["PriceMin"]}
rules={[
{
required: true,
message: "Please confirm your password!",
},
({ getFieldValue }) => ({
validator(rule, value) {
if (
parseInt(value) < parseInt(getFieldValue("PriceMin"))
) {
return Promise.reject(
"Maksimum fiyat minimum fiyattan az olamaz!" //When i delete that row its fix warning, but i need have that error message.
);
}
},
}),
]}
>
<Input
name="Input"
type="number"
disabled={
MyForm.getFieldValue("PriceMin") === undefined ||
MyForm.getFieldValue("PriceMin") === ""
? true
: false
}
placeholder="En yüksek fiyat"
onChange={(e) => updateForm(e.target.value, "PriceMax")}
/>
</Form.Item>
You must do as shown in the example您必须按照示例中所示进行操作
https://ant.design/components/form/#components-form-demo-register https://ant.design/components/form/#components-form-demo-register
The validator should always return a promise on both success and error验证器应始终返回成功和错误的承诺
({ getFieldValue }) => ({
validator(rule, value) {
if (parseInt(value, 10) < parseInt(getFieldValue("PriceMin"), 10)) {
return Promise.reject(
"Maksimum fiyat minimum fiyattan az olamaz!");
}
return Promise.resolve();
}
})
Also you missed a radix parameter in the parseInt你也错过了 parseInt 中的一个基数参数
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.