forked from perscrew/react-native-form-validator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
formTest.js
43 lines (35 loc) · 1.31 KB
/
formTest.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
'use strict';
import React, {Component} from 'react';
import {View, Text, TextInput, TouchableHighlight} from 'react-native';
import ValidationComponent from '../index';
export default class FormTest extends ValidationComponent {
constructor(props) {
super(props);
this.state = {name : "My name", email: "[email protected]", number:"56", date: "2017-03-01"};
}
_onPressButton() {
// Call ValidationComponent validate method
this.validate({
name: {minlength:3, maxlength:7, required: true},
email: {email: true},
number: {numbers: true},
date: {date: 'YYYY-MM-DD'}
});
}
render() {
return (
<View>
<TextInput ref="name" onChangeText={(name) => this.setState({name})} value={this.state.name} />
<TextInput ref="email" onChangeText={(email) => this.setState({email})} value={this.state.email} />
<TextInput ref="number" onChangeText={(number) => this.setState({number})} value={this.state.number} />
<TextInput ref="date" onChangeText={(date) => this.setState({date})} value={this.state.date} />
<TouchableHighlight onPress={this._onPressButton}>
<Text>Submit</Text>
</TouchableHighlight>
<Text>
{this.getErrorMessages()}
</Text>
</View>
);
}
}