-
Notifications
You must be signed in to change notification settings - Fork 124
/
Copy pathDynamicInputForm.tsx
44 lines (38 loc) · 1023 Bytes
/
DynamicInputForm.tsx
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
import { PropsWithChildren } from 'react';
import * as React from 'react';
import Formsy from '../src';
import TestInput from './TestInput';
interface DynamicInputFormProps {
onSubmit: (model: any) => void;
inputName?: string;
}
class DynamicInputForm extends React.Component<PropsWithChildren<DynamicInputFormProps>, { input: any }> {
constructor(props) {
super(props);
this.state = {
input: null,
};
}
private addInput = () => {
const { inputName } = this.props;
this.setState({
input: <TestInput name={inputName} value="" testId="test-input" />,
});
};
public render() {
const { onSubmit, children } = this.props;
const { input } = this.state;
return (
<>
<Formsy onSubmit={onSubmit} data-testid="form">
{input}
{children}
</Formsy>
<button type="button" onClick={this.addInput} data-testid="add-input-btn">
Add input
</button>
</>
);
}
}
export default DynamicInputForm;