[英]Ant.design does not detect custom input component in Form.Item React
So, the main problem is, that antd form does not detect my custom input based on antd standard input: There is a piece of form code (AddProduct):所以,主要问题是,antd 表单没有检测到我基于 antd 标准输入的自定义输入:有一段表单代码(AddProduct):
<Form.Item
className="m-t-10"
name="price"
rules={[
{
required: true,
message: `${t('FORM.ERR.SHOP.PRICE')}`,
},
]}
>
<CurrencyInput size="small" placeholder={t('FORM.SHOP.PRICE_VAT')} name="price" />
</Form.Item>
There is my custom input (CurrencyInput):有我的自定义输入(CurrencyInput):
return (
<Input size={props.size} placeholder={props.placeholder} name={props.name} type="number" prefix={settings[6].value} />
)
The problem is when I try to submit the form it does not detect currency input, throws err that this field is required.问题是当我尝试提交表单时,它没有检测到货币输入,抛出错误,表明该字段是必需的。 Any ideas are it possible to implement custom input, basically, it's more HOC than custom input任何想法都可以实现自定义输入,基本上,它比自定义输入更 HOC
You need to pass to your custom component all props, because Form.Item
pass to there onChange
and value
props您需要将所有道具传递给您的自定义组件,因为Form.Item
传递到那里onChange
和value
道具
function CustomInput({size, placehodler, name, ...restProps}) {
return (
<Input size={size} placeholder={placeholder} name={name}
type="number" prefix={settings[6].value} {...restProps} />
)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.