javascript - antd: Force an Input field to Uppercase - Stack Overflow

i want the text to be upeercase with ant design, i tried this:<Form form={form} layout='vertic

i want the text to be upeercase with ant design, i tried this:

<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.

i want the text to be upeercase with ant design, i tried this:

<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.

Share Improve this question asked Aug 10, 2022 at 21:33 AlexAlex 8011 gold badge8 silver badges21 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 7

You can use onInput event to transform text to uppercase.

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744320251a4568378.html

相关推荐

  • javascript - antd: Force an Input field to Uppercase - Stack Overflow

    i want the text to be upeercase with ant design, i tried this:<Form form={form} layout='vertic

    7天前
    50

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信