-
Notifications
You must be signed in to change notification settings - Fork 1
/
FormExample.js
75 lines (70 loc) · 1.88 KB
/
FormExample.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import React from 'react';
import {View} from 'react-native';
import {Form, FormItem, InputText, FormAction, FORM_ACTIONS} from 'rn-form';
import {ContentText} from '../../common/components/type/ContentText';
import {InputText as InputTextBasic} from '../../common/components/input/InputText';
import {Button} from '../../common/components/Button';
const rules = [
{required: true, message: 'is required!'},
{
pattern: /^\d{1,10}$/,
message: 'idk!',
},
];
function FormExample() {
const form = React.useRef();
const checkUserNameOne = React.useCallback((value, callback) => {
setTimeout(() => {
if (value === '15188888888') {
callback('some');
} else {
callback();
}
}, 2000);
}, []);
return (
<View>
<Form
name="First form"
ref={form}
onFinish={values => {
console.log('Finish:', values);
}}>
<FormItem
name="username"
label="Username 1"
options={{
rules: rules,
}}
/>
<FormItem
name="username2"
label="Username 2"
options={{
validateFirst: true,
rules: rules,
}}>
<InputText placeholder="Some Placeholder" />
</FormItem>
<FormItem
name="username3"
label="Username 3"
options={{
// initialValue: 'My name',
// validateFirst: true,
rules,
}}
showError={false}
showLabel={false}>
<InputTextBasic label="Username 3" />
</FormItem>
<FormAction title="Submit" />
<FormAction title="RESET" action={FORM_ACTIONS.RESET} />
<FormAction title="VALIDATE" action={FORM_ACTIONS.VALIDATE}>
<Button buttonText={'Validate'} />
</FormAction>
</Form>
</View>
);
}
export {FormExample};