【发布时间】:2019-09-26 16:57:39
【问题描述】:
我在我的应用程序中使用ant design。
https://ant.design/components/table/
我面临一个验证问题。我在演示中实现了表格。当我单击edit 按钮时,它显示input field
我可以添加required 的验证。因此不允许为空。但我希望用户只在input 字段中输入one 或1 个字符,否则会显示错误。
这是我的代码 https://codesandbox.io/s/thirsty-tesla-1nwph
return (
<td {...restProps}>
{editing ? (
<Form.Item style={{ margin: 0 }}>
{getFieldDecorator(dataIndex, {
rules: [
{
required: true,
message: `Please Input ${title}!`
}
],
initialValue: record[dataIndex]
})(getInput())}
</Form.Item>
) : (
children
)}
</td>
);
};
【问题讨论】:
-
在输入字段上使用 maxLength 属性?
-
我很确定 OP 想要文字选项“1”或“one”,在这种情况下,模式属性会起作用。
标签: javascript reactjs antd