简体   繁体   English

Ant 反应中的设计形式

[英]Ant design form in react

help me, setvalue doesn't work.帮帮我,setvalue 不起作用。 but when I remove the name attribute in Form,Item it works normally?但是当我删除 Form,Item 中的 name 属性时它是否正常工作? is there any way without removing the name attribute and still working properly?有没有办法不删除名称属性并仍然正常工作? antd https://codesandbox.io/s/21jbmg?file=/demo.js antd https://codesandbox.io/s/21jbmg?file=/demo.js

import { Form, Input } from "antd";
import React, { useState } from "react";

const App = () => {
 const [valuess, setValue] = useState("nguyen");
 const onInputChange = (e) => {
   setValue(e.target.value);
   setValue(FormatName);
};
function FormatName(str) {
  return str
   .normalize("NFD")
   .replace(/[\u0300-\u036f]/g, "")
   .replace(/[đĐ]/g, (m) => (m === "đ" ? "d" : "D"))
   .toUpperCase();
}
 return (
  <Form name="basic">
    <Form.Item name="Username" label="Username">
      <Input onChange={onInputChange} value={valuess} />
    </Form.Item>
  </Form>
 );
};
export default App;

i think your form is working bad, because a form need to be send for onFinish function, and previously in the input you can formatted the value for it, obviously you need a submit button我认为你的表单工作不好,因为需要为 onFinish function 发送一个表单,之前在输入中你可以为它格式化值,显然你需要一个提交按钮

let me share my obs:让我分享我的观点:

function FormatName(str) {
  return str
   .normalize("NFD")
   .replace(/[\u0300-\u036f]/g, "")
   .replace(/[đĐ]/g, (m) => (m === "đ" ? "d" : "D"))
   .toUpperCase();
}

<Form name="basic"   onFinish={handleFinish}>
    <Form.Item name="Username" label="Username">
      <Input onChange={onInputChange} normalize={(value) => FormatName(value)} value={valuess} />
    </Form.Item>
<Button htmlType="submit" size="middle" type="primary">
            {t('common:onboarding.continue')}
          </Button>
  </Form>

why do you need this function onFinish?为什么你需要这个 function onFinish? because this will be executed if everything is ok, without errors and so on因为如果一切正常,没有错误等,这将被执行

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM