【发布时间】:2019-08-16 22:28:22
【问题描述】:
我正在尝试在单击提交按钮时验证文本字段。但我总是得到错误-
TypeError: undefined is not an object (evalating 'props.deviceLocale') on my emulator.
(我使用的是安卓模拟器)。
但是我在我的代码中没有使用“deviceLocale”。我不知道我的代码中是否需要它。
这是我的代码:
import React, {Component} from 'react';
import { View, Text, TouchableOpacity, TextInput } from 'react-native';
import ValidationComponent from 'react-native-form-validator';
export default class App extends ValidationComponent {
constructor() {
super()
this.state = {
name: "abc"
}
}
_onPressButton() {
this.validate({
name: {minlength: 3, maxlength: 7, required: true},
});
}
render() {
return (
<View>
<TextInput
ref = "name"
onChangeText = {(name) => this.setState({name})}
value = {this.state.name}
/>
<TouchableOpacity onPress = {this._onPressButton}>
<Text>Submit</Text>
</TouchableOpacity>
</View>
)
}
}
错误捕捉:
【问题讨论】:
-
请添加您的验证方法的代码,以及这个错误究竟是什么时候发生的?点击按钮?
-
@SurajMalviya,验证方法的代码是什么意思?我问是因为我是新手。我正在 _onPressButton() 中验证我唯一的文本字段。按下按钮时不会发生错误。它甚至在加载初始页面之前发生。
标签: android react-native android-emulator