在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/HTML/ 關于 ant design mobile 表單驗證的 getFieldProps

關于 ant design mobile 表單驗證的 getFieldProps問題

如何寫出自定義驗證規(guī)則?

 <List renderHeader={() => 'test'}>
                        <InputItem
                            {...getFieldProps('phone',{rules: [{required: true,message:"123"}],})}
                            type="phone"
                            placeholder="input your phone"
                            error={getFieldError('phone')?true:false}
                        >手機號碼</InputItem>
    
                    </List>
                    

現(xiàn)在的規(guī)則是必填,當然也可以用其他的定義好的規(guī)則 比如 type:string子類的,
但是可以設置自定義的驗證函數(shù)嗎?

回答
編輯回答
誮惜顏

當然可以,使用validate方法就可以了。在文檔中有鏈接。

2017年4月20日 02:37
編輯回答
局外人

驗證不是這樣寫的,類似這種

const { getFieldDecorator } = this.props.form;

<FormItem {...formItemLayout} label="Name">
  {getFieldDecorator('username', {
    rules: [{
      required: true,
      message: 'Please input your name',
    }],
  })(
    <Input placeholder="Please input your name" />
  )}
</FormItem>
2017年2月20日 02:21
編輯回答
薔薇花
            <InputItem
                {...getFieldProps('phone',{rules: [
                    {required: true,message:"必填啊"},
                    {validator(rule, value, callback, source, options){
                        var errors = [];
                        console.log(value,"Xx")
                        if(value==1){
                            callback("wocao  111");
                        }else{
                            callback(errors);
                        }

                    }}

                ],})}
                type="phone"
                placeholder="input your phone"
                error={getFieldError('phone')?true:false}
            >手機號碼</InputItem>
            

getFieldDecorator 和 getFieldProps相似 只是寫法不同。
https://github.com/react-comp...

自定義驗證就是參數(shù) validator
圖片描述

2018年4月25日 21:25