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
import joi from 'joi';
// import { Input, Select, Textarea, CheckList, RadioList } from '@ferdotnet/reactive-form-builder';
// or, import here your custom inputs if needed
const schema = {
education: {
value: '',
label: 'Education',
input: Select,
options: [
{ value: 'autodidact', label: 'Autodidact' },
{ value: 'graduated', label: 'Graduated' },
{ value: 'ungraduated', label: 'Ungraduated' }
],
joi: joi.string().required().messages({
'string.empty': messages.REQUIRED
})
},
description: {
value: '',
label: 'Description',
input: Textarea,
joi: joi.string().required().messages({
'string.empty': messages.REQUIRED
})
},
workPreference: {
value: [],
label: 'Work preference',
input: CheckList,
options: [
{ value: 'qa', label: 'QA' },
{ value: 'devops', label: 'Devops' },
{ value: 'frontend', label: 'Front end' },
{ value: 'backend', label: 'Back end' }
],
joi: joi.array().min(1).required().messages({
'array.min': messages.REQUIRED
})
},
contracting: {
value: '',
label: 'Contracting',
input: RadioList,
options: [
{ value: 'contractor', label: 'Contractor' },
{ value: 'employee', label: 'As employee' }
],
joi: joi.string().required().messages({
'string.empty': messages.REQUIRED
})
}
}
export default schema;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import React from 'react';
import { useReactiveFormBuilder, ReactiveFormBuilder } from '@ferdotnet/reactive-form-builder';
import schema from './schema';
const MyComponent = () => {
const handler = useReactiveFormBuilder(schema, true); // Second param is to debug
const handleSubmit = (event: React.FormEvent) => {
event.preventDefault();
alert(JSON.stringify(handler.data));
};
return (
<form onSubmit={handleSubmit}>
<ReactiveFormBuilder handler={handler} />
<button type="submit" disabled={!handler.valid}>
Submit
</button>
</form>
);
};
export default MyComponent;