【问题标题】:Try to add new validation rule in reactjs material尝试在 reactjs 材料中添加新的验证规则
【发布时间】:2017-11-21 06:17:21
【问题描述】:

我试图添加新的验证规则。我正在使用反应材料 1.0

这是我添加新规则但出错的代码

ValidatorForm.addValidationRule('isCanRequired', (value) => {
        if(this.state.canSameAccount){
          if(value==null || value==="" || value===undefined)
            return false;
        }
        return true;
    });

这是我添加此新规则的字段

<TextValidator fullWidth name="canAddress1" value={this.state.canAddress1}
                          validators={['isCanRequired']} errorMessages={['Please enter your street address 1']}
                          label="Enter Street Address 1*" onChange={this.handleChange('canAddress1')} />

这是我点击提交按钮时的错误截图

【问题讨论】:

  • 嗨!您在组件生命周期的哪种方法中添加验证规则?我已在 componentWillMount 中添加了此代码,并让您的代码正常工作。
  • 我正在添加 componentWillMount 但代码不起作用

标签: forms reactjs validation material-ui


【解决方案1】:

我得到了答案 由于 react-material-ui-form-validator 的 beta 版本。需要换ValidatorForm的包

import {ValidatorForm} from 'react-material-ui-form-validator'

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-12-29
    • 2020-02-14
    • 2020-10-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-10
    相关资源
    最近更新 更多