以前,在Redux-Form V5中,我从render函数内部访问错误email.error
和password.error
。有没有办法使用reduxForm V7从容器内部访问Reduce-form错误?
在V7中,我的CSS是给我的悲伤做这种方式:通过renderInput()
const renderInput = (field) => {
const { meta: { touched, error } } = field
return (
<div>
<input type={field.type} placeholder={field.placeholder} {...field.input} />
<div className="inputErrorText">
{touched ? error : ''} // this doesnt work due to my CSS
</div>
</div>
)
}
// ...inside the Container:
<div className="ui left icon input">
<i className="user icon"></i>
<Field
name="email"
component={renderInput}
type="text"
placeholder="Enter your Email"
/>
</div>
// Below is the old way I was doing it
{/*email.touched && email.error && <div className="inputErrorText">{email.error}</div>*/}
如果我渲染错误,CSS被错位由于看起来像一些相对+位置的绝对理由,所以我需要在上面的代码底部显示最后一个div的错误。
如何处理在renderInput()
之外和/或<form>
其他地方渲染字段错误。我认为我的问题围绕renderInput()
的输入参数field
。如何在容器中访问它?是否可以在this.props
的任何地方使用?
我离开这个答案“没有回答”一段时间。我今天刚刚重新访问了这个例子,在进一步细化之后,我现在认为答案涉及“解除状态”成为第一个共同的祖先,意思是这个表单所在的容器。 – agm1984