[英]antd: Force an Input field to Uppercase
i want the text to be upeercase with ant design, i tried this:我希望文本使用 ant 设计大写,我试过这个:
<Form form={form} layout='vertical' autoComplete='off'>
<Form.Item
name='apellido_empleado'
label='Apellidos'
rules={[
{
required: true,
message: 'Por favor ingrese los apellidos',
transform: (v) => v.toUpperCase(),
},
]}>
<Input />
</Form.Item>
it seems that the property transform only work for validations.似乎属性转换仅适用于验证。
You can use onInput
event to transform text to uppercase.您可以使用onInput
事件将文本转换为大写。
const [form] = Form.useForm<{ apellido_empleado: string }>();
return (
<>
<Form form={form} layout='vertical' autoComplete='off' sub>
<Form.Item
name='apellido_empleado'
label='Apellidos'
rules={[
{
required: true,
message: 'Por favor ingrese los apellidos'
},
]}>
<Input onInput={e => e.target.value = e.target.value.toUpperCase()} />
</Form.Item>
</Form>
<Button onClick={() => console.log(form.getFieldValue('apellido_empleado'))}>Print value</Button>
</>
);
In typescript (e.target as HTMLInputElement).value
在 typescript (e.target as HTMLInputElement).value
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.