-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.jsx
48 lines (43 loc) · 1.35 KB
/
index.jsx
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
import React, { Component } from 'react';
import ReactDOM from 'react-dom';
import Form from '../../src/form';
import { isAlpha } from 'validator';
import MyCustomInput from './my-custom-input';
class Root extends Component {
constructor(props) {
super(props);
}
render() {
return (
<Form>
<h2>Form with custom input</h2>
<Form.CustomInput>
<MyCustomInput
name='name'
placeHolder='Type your name here...'
type='text'
validate={(value) => {
let valid = true;
let errorMessage = '';
if (!value.length) {
valid = false;
errorMessage = 'This field is required';
} else if (!isAlpha(value.replace(/\s/g, ''))) {
valid = false;
errorMessage = 'You must enter only characters';
}
return { valid, errorMessage };
}}
/>
</Form.CustomInput>
<Form.SubmitButton onClick={(formData) => console.log('Form Data', formData)}>
Submit Form
</Form.SubmitButton>
<Form.ResetButton>
Reset Form
</Form.ResetButton>
</Form>
);
}
}
ReactDOM.render(<Root/>, document.getElementById('reactApplication'));