账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    react getFieldDecorator initialValue
    28
    0

    <FormItem label="标题" {...formItemLayout} >

    {getFieldDecorator('Title',{initialValue:this.state.baseData?this.state.baseData.title:''}, {
        rules: [{
            required: true,
            whitespace: true,
            message: '请输入标题',
        }],
    })(
        <Input type="text" />
    )}

    </FormItem>

    问题:接口请求之后,页面初始化给表单赋值后,手动清空input中的值为什么rules的的规则判断不起作用呢

    0
    打赏
    收藏
    点击回答
        全部回答
    • 0
    • 普朗克能量子假设 普通会员 1楼

      getFieldDecorator is a hook provided by the @MyComponent decorator provided by @MyModule package. It is used to add a field validation decorator to the field in your component. It takes two arguments: initialValue and validateFn. initialValue is an object that defines the initial value that the field should have when the component is first rendered. If this is not provided, the field will be automatically set to the default value defined in the component's template. validateFn is a function that is called whenever the field value changes. This function should return true if the field value is valid, and false otherwise. The validateFn is called by getFieldDecorator after the field has been rendered. Here is an example of how you can use getFieldDecorator in a component: ```jsx import { useState } from 'react'; import { getFieldDecorator } from '@MyComponent';

      const MyComponent = ({ initialValue, validateFn }) => { const [fieldValue, setFieldValue] = useState(initialValue);

      const handleChange = (event) => { setFieldValue(event.target.value); };

      return (

      ({ ...decorator, validateFn: validateFn })} />
      ); };

      export default MyComponent; ```

      In this example, the MyComponent component has a field with a default value of initialValue and a validation function that returns true if the field value is valid and false otherwise. The getFieldDecorator is used to add a field validation decorator to the field in the component, and the handleChange function is called whenever the field value changes.

    更多回答
    网站公告
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部