Reactjs Redux表单6.1.1-模糊验证不适用于react native
我正在开发react native(Android),我正在使用redux form 6.1.1 我注意到一个奇怪的行为,即当我从输入字段中移除焦点(模糊)时,redux表单不执行验证,但是提交验证按预期工作 请带我到这里。下面是我的代码 文本字段组件Reactjs Redux表单6.1.1-模糊验证不适用于react native,reactjs,react-native,redux-form,react-native-android,Reactjs,React Native,Redux Form,React Native Android,我正在开发react native(Android),我正在使用redux form 6.1.1 我注意到一个奇怪的行为,即当我从输入字段中移除焦点(模糊)时,redux表单不执行验证,但是提交验证按预期工作 请带我到这里。下面是我的代码 文本字段组件 <TextInput keyboardType={ textType ? textType : 'default' } onChangeText={ (val) => onChange(val) } value={ val
<TextInput
keyboardType={ textType ? textType : 'default' }
onChangeText={ (val) => onChange(val) }
value={ value }
underlineColorAndroid="transparent"
style={ styleInput }
{...this.props}
/>
{/* Error message */}
<View>
{
touched && error ?
<Text>{error}</Text>
: null
}
</View>
const {
input: { value, onChange, onBlur }
} = this.props;
...
...
<TextInput
keyboardType={ textType ? textType : 'default' }
onChangeText={ val => onChange(val) }
onBlur={ val => onBlur(val) } {/* <--- added onBlur function */}
value={ value }
underlineColorAndroid="transparent"
style={ styleInput }
{...this.props}
/>
{/* Error message */}
<View>
{
touched && error ?
<Text>{error}</Text>
: null
}
</View>
注意:我观察到,从触摸和错误条件错误包含所需的错误消息,但即使切换/聚焦到另一个输入字段后,触摸仍然为假。当我点击提交按钮时,触摸标志设置为true。我找到了解决方法,但如果他们的方法更好,请更新 下面是我的更新代码(带有工作模糊事件) 更新的文本字段组件
<TextInput
keyboardType={ textType ? textType : 'default' }
onChangeText={ (val) => onChange(val) }
value={ value }
underlineColorAndroid="transparent"
style={ styleInput }
{...this.props}
/>
{/* Error message */}
<View>
{
touched && error ?
<Text>{error}</Text>
: null
}
</View>
const {
input: { value, onChange, onBlur }
} = this.props;
...
...
<TextInput
keyboardType={ textType ? textType : 'default' }
onChangeText={ val => onChange(val) }
onBlur={ val => onBlur(val) } {/* <--- added onBlur function */}
value={ value }
underlineColorAndroid="transparent"
style={ styleInput }
{...this.props}
/>
{/* Error message */}
<View>
{
touched && error ?
<Text>{error}</Text>
: null
}
</View>
const{
输入:{value,onChange,onBlur}
}=这是道具;
...
...
onChange(val)}
onBlur={val=>onBlur(val)}{/*
{/*错误消息*/}
{
触摸错误(&R)?
{错误}
:null
}
我刚刚将redux表单字段提供的onBlur props/function传递给TextInput字段的onBlur function(由react native提供),一切都正常工作。react dom也有同样的问题。您的模糊解决方案对我不起作用,但如果您能共享代码片段,我会很有帮助。