admin管理员组文章数量:1332383
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. And validate if PriceMax is bigger than 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." 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>
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. And validate if PriceMax is bigger than 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." 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>
Share
Improve this question
asked Nov 2, 2021 at 9:13
Ugurcan UcarUgurcan Ucar
4061 gold badge10 silver badges32 bronze badges
1 Answer
Reset to default 6You must do as shown in the example
https://ant.design/ponents/form/#ponents-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
本文标签:
版权声明:本文标题:javascript - Ant design Form "Warning: `callback` is deprecated. Please return a promise instead." Error in cu 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742297141a2448962.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论