假设我有包含以下字段的登录表单:
const Email = t.refinement(t.String, (str) => {
const reg = /[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/;
return reg.test(str);
});
const Password = t.refinement(t.String, (str) => {
return str.length >= 6; // minimum password length should be 6 symbols
});
const Person = t.struct({
email: Email,
password: Password,
});
数据用户输入字段验证,然后我向身份验证服务器发送请求,服务器另外验证接收到的数据,结果证明没有用户具有此类凭据。所以它根据响应返回:
{
success: false,
data: { password: ['User with such credentials is not found.'] }
}
问题是,如何将动态错误设置为 tcomb 属性?比如:
this.refs.form.getComponent('password').refs.input.addError(someError);
有可能吗?