envoc-form 4.0.1-11 → 4.0.1-12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5117 -12
- package/es/AddressInput/AddressInput.d.ts +10 -0
- package/es/AddressInput/AddressInput.js +10 -0
- package/es/ConfirmBaseForm/ConfirmBaseForm.d.ts +14 -0
- package/es/ConfirmBaseForm/ConfirmBaseForm.js +6 -0
- package/es/ConfirmDeleteForm/ConfirmDeleteForm.d.ts +13 -0
- package/es/ConfirmDeleteForm/ConfirmDeleteForm.js +5 -0
- package/es/DatePicker/DatePickerGroup.d.ts +5 -0
- package/es/DatePicker/DatePickerGroup.js +5 -0
- package/es/DatePicker/StringDateOnlyPickerGroup.d.ts +5 -0
- package/es/DatePicker/StringDateOnlyPickerGroup.js +5 -0
- package/es/DatePicker/StringDatePickerGroup.d.ts +5 -0
- package/es/DatePicker/StringDatePickerGroup.js +5 -0
- package/es/Field/Field.d.ts +6 -0
- package/es/Field/FieldErrorScrollTarget.d.ts +1 -0
- package/es/Field/FieldErrorScrollTarget.js +1 -0
- package/es/Field/StandAloneInput.d.ts +4 -0
- package/es/Field/StandAloneInput.js +1 -0
- package/es/Field/useStandardField.d.ts +6 -0
- package/es/Field/useStandardField.js +8 -9
- package/es/FieldArray/FieldArray.d.ts +9 -0
- package/es/FieldArray/FieldArray.js +5 -0
- package/es/File/FileGroup.d.ts +2 -0
- package/es/File/FileGroup.js +1 -0
- package/es/Form/FocusError.d.ts +2 -0
- package/es/Form/FocusError.js +1 -0
- package/es/Form/Form.d.ts +6 -0
- package/es/Form/Form.js +1 -0
- package/es/Form/FormBasedPreventNavigation.d.ts +3 -1
- package/es/Form/FormBasedPreventNavigation.js +12 -62
- package/es/Form/LegacyFormBasedPreventNavigation.d.ts +17 -0
- package/es/Form/LegacyFormBasedPreventNavigation.js +69 -0
- package/es/Form/NewFormBasedPreventNavigation.d.ts +14 -0
- package/es/Form/NewFormBasedPreventNavigation.js +39 -0
- package/es/Form/ServerErrorContext.d.ts +1 -0
- package/es/Form/ServerErrorContext.js +1 -0
- package/es/FormActions.d.ts +6 -0
- package/es/FormActions.js +1 -0
- package/es/FormDefaults.d.ts +1 -0
- package/es/FormDefaults.js +1 -0
- package/es/Group.d.ts +5 -3
- package/es/Group.js +2 -2
- package/es/Input/IconInputGroup.d.ts +3 -0
- package/es/Input/IconInputGroup.js +1 -0
- package/es/Input/InputGroup.d.ts +1 -1
- package/es/Input/InputGroup.js +2 -2
- package/es/Input/MoneyInputGroup.d.ts +2 -0
- package/es/Input/MoneyInputGroup.js +1 -0
- package/es/Input/NumberInputGroup.d.ts +2 -0
- package/es/Input/NumberInputGroup.js +1 -0
- package/es/Input/StringInputGroup.d.ts +1 -0
- package/es/Input/StringInputGroup.js +1 -0
- package/es/Normalization/normalizers.d.ts +2 -0
- package/es/Normalization/normalizers.js +2 -0
- package/es/Select/BooleanSelectGroup.d.ts +1 -0
- package/es/Select/BooleanSelectGroup.js +1 -0
- package/es/Select/NumberSelectGroup.d.ts +2 -0
- package/es/Select/NumberSelectGroup.js +2 -0
- package/es/Select/SelectGroup.d.ts +6 -0
- package/es/Select/SelectGroup.js +1 -0
- package/es/Select/StringSelectGroup.d.ts +2 -0
- package/es/Select/StringSelectGroup.js +2 -0
- package/es/StandardFormActions.d.ts +5 -0
- package/es/StandardFormActions.js +1 -0
- package/es/SubmitFormButton.d.ts +3 -0
- package/es/SubmitFormButton.js +1 -0
- package/es/TextArea/TextAreaGroup.d.ts +1 -0
- package/es/TextArea/TextAreaGroup.js +1 -1
- package/es/Validation/validators.d.ts +3 -0
- package/es/Validation/validators.js +3 -2
- package/es/setupTests.d.ts +1 -0
- package/es/setupTests.js +1 -0
- package/lib/AddressInput/AddressInput.d.ts +10 -0
- package/lib/AddressInput/AddressInput.js +10 -0
- package/lib/ConfirmBaseForm/ConfirmBaseForm.d.ts +14 -0
- package/lib/ConfirmBaseForm/ConfirmBaseForm.js +6 -0
- package/lib/ConfirmDeleteForm/ConfirmDeleteForm.d.ts +13 -0
- package/lib/ConfirmDeleteForm/ConfirmDeleteForm.js +5 -0
- package/lib/DatePicker/DatePickerGroup.d.ts +5 -0
- package/lib/DatePicker/DatePickerGroup.js +5 -0
- package/lib/DatePicker/StringDateOnlyPickerGroup.d.ts +5 -0
- package/lib/DatePicker/StringDateOnlyPickerGroup.js +5 -0
- package/lib/DatePicker/StringDatePickerGroup.d.ts +5 -0
- package/lib/DatePicker/StringDatePickerGroup.js +5 -0
- package/lib/Field/Field.d.ts +6 -0
- package/lib/Field/FieldErrorScrollTarget.d.ts +1 -0
- package/lib/Field/FieldErrorScrollTarget.js +1 -0
- package/lib/Field/StandAloneInput.d.ts +4 -0
- package/lib/Field/StandAloneInput.js +1 -0
- package/lib/Field/useStandardField.d.ts +6 -0
- package/lib/Field/useStandardField.js +8 -9
- package/lib/FieldArray/FieldArray.d.ts +9 -0
- package/lib/FieldArray/FieldArray.js +5 -0
- package/lib/File/FileGroup.d.ts +2 -0
- package/lib/File/FileGroup.js +1 -0
- package/lib/Form/FocusError.d.ts +2 -0
- package/lib/Form/FocusError.js +1 -0
- package/lib/Form/Form.d.ts +6 -0
- package/lib/Form/Form.js +1 -0
- package/lib/Form/FormBasedPreventNavigation.d.ts +3 -1
- package/lib/Form/FormBasedPreventNavigation.js +13 -60
- package/lib/Form/LegacyFormBasedPreventNavigation.d.ts +17 -0
- package/lib/Form/LegacyFormBasedPreventNavigation.js +72 -0
- package/lib/Form/NewFormBasedPreventNavigation.d.ts +14 -0
- package/lib/Form/NewFormBasedPreventNavigation.js +42 -0
- package/lib/Form/ServerErrorContext.d.ts +1 -0
- package/lib/Form/ServerErrorContext.js +1 -0
- package/lib/FormActions.d.ts +6 -0
- package/lib/FormActions.js +1 -0
- package/lib/FormDefaults.d.ts +1 -0
- package/lib/FormDefaults.js +1 -0
- package/lib/Group.d.ts +5 -3
- package/lib/Group.js +2 -2
- package/lib/Input/IconInputGroup.d.ts +3 -0
- package/lib/Input/IconInputGroup.js +1 -0
- package/lib/Input/InputGroup.d.ts +1 -1
- package/lib/Input/InputGroup.js +2 -2
- package/lib/Input/MoneyInputGroup.d.ts +2 -0
- package/lib/Input/MoneyInputGroup.js +1 -0
- package/lib/Input/NumberInputGroup.d.ts +2 -0
- package/lib/Input/NumberInputGroup.js +1 -0
- package/lib/Input/StringInputGroup.d.ts +1 -0
- package/lib/Input/StringInputGroup.js +1 -0
- package/lib/Normalization/normalizers.d.ts +2 -0
- package/lib/Normalization/normalizers.js +2 -0
- package/lib/Select/BooleanSelectGroup.d.ts +1 -0
- package/lib/Select/BooleanSelectGroup.js +1 -0
- package/lib/Select/NumberSelectGroup.d.ts +2 -0
- package/lib/Select/NumberSelectGroup.js +2 -0
- package/lib/Select/SelectGroup.d.ts +6 -0
- package/lib/Select/SelectGroup.js +1 -0
- package/lib/Select/StringSelectGroup.d.ts +2 -0
- package/lib/Select/StringSelectGroup.js +2 -0
- package/lib/StandardFormActions.d.ts +5 -0
- package/lib/StandardFormActions.js +1 -0
- package/lib/SubmitFormButton.d.ts +3 -0
- package/lib/SubmitFormButton.js +1 -0
- package/lib/TextArea/TextAreaGroup.d.ts +1 -0
- package/lib/TextArea/TextAreaGroup.js +1 -1
- package/lib/Validation/validators.d.ts +3 -0
- package/lib/Validation/validators.js +3 -2
- package/lib/setupTests.d.ts +1 -0
- package/lib/setupTests.js +3 -0
- package/package.json +9 -6
- package/src/AddressInput/AddressInput.tsx +10 -0
- package/src/AddressInput/__snapshots__/AddressInput.test.tsx.snap +4 -0
- package/src/ConfirmBaseForm/ConfirmBaseForm.tsx +14 -0
- package/src/ConfirmDeleteForm/ConfirmDeleteForm.tsx +13 -0
- package/src/DatePicker/DatePicker.test.tsx +1 -1
- package/src/DatePicker/DatePickerGroup.tsx +5 -2
- package/src/DatePicker/StringDateOnlyPickerGroup.tsx +5 -0
- package/src/DatePicker/StringDatePickerGroup.tsx +6 -0
- package/src/Field/Field.tsx +6 -1
- package/src/Field/FieldErrorScrollTarget.tsx +1 -0
- package/src/Field/StandAloneInput.tsx +4 -0
- package/src/Field/useStandardField.ts +13 -9
- package/src/FieldArray/FieldArray.tsx +9 -0
- package/src/File/FileGroup.tsx +2 -0
- package/src/Form/FocusError.tsx +3 -0
- package/src/Form/Form.tsx +6 -0
- package/src/Form/FormBasedPreventNavigation.tsx +26 -60
- package/src/Form/LegacyFormBasedPreventNavigation.tsx +77 -0
- package/src/Form/NewFormBasedPreventNavigation.tsx +59 -0
- package/src/Form/ServerErrorContext.ts +1 -0
- package/src/FormActions.tsx +7 -0
- package/src/FormDefaults.ts +1 -0
- package/src/Group.tsx +8 -4
- package/src/Input/IconInputGroup.tsx +3 -0
- package/src/Input/InputGroup.tsx +3 -1
- package/src/Input/MoneyInputGroup.tsx +2 -0
- package/src/Input/NumberInputGroup.tsx +2 -0
- package/src/Input/StringInputGroup.tsx +1 -0
- package/src/Input/__Tests__/__snapshots__/IconInputGroup.test.tsx.snap +1 -0
- package/src/Input/__Tests__/__snapshots__/MoneyInputGroup.test.tsx.snap +1 -0
- package/src/Input/__Tests__/__snapshots__/NumberInputGroup.test.tsx.snap +1 -0
- package/src/Input/__Tests__/__snapshots__/StringInputGroup.test.tsx.snap +1 -0
- package/src/Normalization/normalizers.ts +2 -0
- package/src/Select/BooleanSelectGroup.tsx +1 -0
- package/src/Select/NumberSelectGroup.tsx +2 -0
- package/src/Select/SelectGroup.tsx +6 -0
- package/src/Select/StringSelectGroup.tsx +2 -0
- package/src/StandardFormActions.tsx +5 -0
- package/src/SubmitFormButton.tsx +3 -0
- package/src/TextArea/TextAreaGroup.tsx +1 -1
- package/src/Validation/validators.ts +3 -2
- package/src/__Tests__/FormTestBase.tsx +7 -6
- package/src/__Tests__/RealisticForm.test.tsx +82 -0
- package/src/setupTests.ts +1 -0
- package/es/__Tests__/FormTestBase.d.ts +0 -27
- package/es/__Tests__/FormTestBase.js +0 -83
- package/es/__Tests__/index.d.ts +0 -2
- package/es/__Tests__/index.js +0 -2
- package/lib/__Tests__/FormTestBase.d.ts +0 -27
- package/lib/__Tests__/FormTestBase.js +0 -86
- package/lib/__Tests__/index.d.ts +0 -2
- package/lib/__Tests__/index.js +0 -8
@@ -5,10 +5,15 @@ import SubmitFormButton from './SubmitFormButton';
|
|
5
5
|
import { FormDefaults } from './FormDefaults';
|
6
6
|
|
7
7
|
export interface StandardFormActionsProps {
|
8
|
+
/** Allow the form to be submitted without any changes. By default this is not allowed. */
|
8
9
|
allowPristineSubmit?: boolean;
|
10
|
+
/** The cancel button's `onClick`.
|
11
|
+
* @defaultValue `window.history.back()`
|
12
|
+
*/
|
9
13
|
handleCancel?: MouseEventHandler<HTMLButtonElement>;
|
10
14
|
}
|
11
15
|
|
16
|
+
/** Standard submit and cancel buttons. */
|
12
17
|
export default function StandardFormActions({
|
13
18
|
allowPristineSubmit,
|
14
19
|
handleCancel,
|
package/src/SubmitFormButton.tsx
CHANGED
@@ -5,7 +5,9 @@ import { FormDefaults } from './FormDefaults';
|
|
5
5
|
|
6
6
|
export interface SubmitFormButtonProps
|
7
7
|
extends Omit<React.HTMLProps<HTMLButtonElement>, 'type'> {
|
8
|
+
/** Allow the form to be submitted without any changes. By default this is not allowed. */
|
8
9
|
allowPristineSubmit?: boolean;
|
10
|
+
/** Text to display on the button. Default text is 'Submit'. */
|
9
11
|
children?: React.ReactNode;
|
10
12
|
}
|
11
13
|
|
@@ -46,6 +48,7 @@ function SubmitFormButton(
|
|
46
48
|
);
|
47
49
|
}
|
48
50
|
|
51
|
+
/** Generic submit button for forms. */
|
49
52
|
export default React.forwardRef(
|
50
53
|
SubmitFormButton
|
51
54
|
) as React.FunctionComponent<SubmitFormButtonProps>;
|
@@ -14,7 +14,6 @@ export interface TextAreaGroupProps
|
|
14
14
|
icon?: React.ReactNode;
|
15
15
|
}
|
16
16
|
|
17
|
-
/** generic controlled <textarea/> wrapped by a Group */
|
18
17
|
function TextAreaGroup(
|
19
18
|
{
|
20
19
|
input,
|
@@ -57,6 +56,7 @@ function TextAreaGroup(
|
|
57
56
|
);
|
58
57
|
}
|
59
58
|
|
59
|
+
/** Generic controlled `<textarea/>` wrapped by a `<Group/>` */
|
60
60
|
const TextAreaGroupWithRef = React.forwardRef(
|
61
61
|
TextAreaGroup
|
62
62
|
) as React.ComponentType<TextAreaGroupProps>;
|
@@ -9,7 +9,7 @@ export const required = (value: any) =>
|
|
9
9
|
? undefined
|
10
10
|
: 'Required';
|
11
11
|
|
12
|
-
|
12
|
+
/** Asserts that the value is a certain number of characters. numbers are coerced to a string */
|
13
13
|
export const length =
|
14
14
|
(len: number) => (value: string | number | undefined | null) => {
|
15
15
|
const hasError = getLengthOfValue(value) !== len;
|
@@ -54,13 +54,14 @@ export const minValue = (min: number) => (value: number | undefined | null) => {
|
|
54
54
|
return !hasError ? undefined : `Minimum value ${min} not met`;
|
55
55
|
};
|
56
56
|
|
57
|
+
/** Validate for a ZIP Code. Accepts formats: ##### and #####-#### */
|
57
58
|
export const zipCode = (value: string | undefined | null) => {
|
58
59
|
return value && !/^[0-9]{5}(?:-[0-9]{4})?$/.test(value)
|
59
60
|
? 'Invalid ZIP Code'
|
60
61
|
: undefined;
|
61
62
|
};
|
62
63
|
|
63
|
-
|
64
|
+
/** One of the validators provided must be true. */
|
64
65
|
export const any =
|
65
66
|
<TValue>(validatorList: ValidationFunction<TValue>[]) =>
|
66
67
|
(value: TValue) => {
|
@@ -1,4 +1,3 @@
|
|
1
|
-
import '@testing-library/jest-dom/extend-expect';
|
2
1
|
import { HashRouter } from 'react-router-dom';
|
3
2
|
import { Form, FormBuilderProp } from '../';
|
4
3
|
import { ValidatedApiResult } from '../Validation/ValidatedApiResult';
|
@@ -6,23 +5,25 @@ import { ValidatedApiResult } from '../Validation/ValidatedApiResult';
|
|
6
5
|
interface FormTestBaseProps<TForm extends object> {
|
7
6
|
children: (formBuilder: FormBuilderProp<TForm>) => JSX.Element;
|
8
7
|
initialValues?: TForm;
|
8
|
+
handleSubmit?: (data: TForm | FormData) => Promise<ValidatedApiResult>;
|
9
9
|
}
|
10
10
|
|
11
11
|
export default function FormTestBase<TForm extends PersonDto>({
|
12
12
|
children,
|
13
13
|
initialValues,
|
14
|
+
handleSubmit,
|
14
15
|
}: FormTestBaseProps<TForm>) {
|
15
16
|
return (
|
16
17
|
<HashRouter>
|
17
|
-
<Form
|
18
|
+
<Form
|
19
|
+
onSubmit={handleSubmit ? handleSubmit : onSubmit}
|
20
|
+
initialValues={initialValues}>
|
18
21
|
{children}
|
19
22
|
</Form>
|
20
23
|
</HashRouter>
|
21
24
|
);
|
22
25
|
|
23
|
-
async function onSubmit(
|
24
|
-
data: PersonDto | FormData
|
25
|
-
): Promise<ValidatedApiResult> {
|
26
|
+
async function onSubmit(data: TForm | FormData): Promise<ValidatedApiResult> {
|
26
27
|
const isFormData = data instanceof FormData;
|
27
28
|
const result = await fetch('/api/submit', {
|
28
29
|
body: isFormData ? data : JSON.stringify(data),
|
@@ -43,7 +44,7 @@ export default function FormTestBase<TForm extends PersonDto>({
|
|
43
44
|
}
|
44
45
|
}
|
45
46
|
|
46
|
-
interface PersonDto {
|
47
|
+
export interface PersonDto {
|
47
48
|
name?: string | undefined;
|
48
49
|
nameWithIcon?: string | undefined;
|
49
50
|
numberOfArms?: number;
|
@@ -0,0 +1,82 @@
|
|
1
|
+
import { render, screen, waitFor } from '@testing-library/react';
|
2
|
+
import user from '@testing-library/user-event';
|
3
|
+
import FormTestBase from './FormTestBase';
|
4
|
+
import { Form, StringInputGroup, ValidatedApiResult } from '../';
|
5
|
+
import { PersonDto } from '../__Tests__/FormTestBase';
|
6
|
+
import StandardFormActions from '../StandardFormActions';
|
7
|
+
import { validators } from '../';
|
8
|
+
|
9
|
+
const handleSubmitMock = jest.fn((value: PersonDto | FormData) => {
|
10
|
+
//return value;
|
11
|
+
return new Promise<ValidatedApiResult>((res, rej) => {
|
12
|
+
setTimeout(() => {
|
13
|
+
res({});
|
14
|
+
}, 15);
|
15
|
+
});
|
16
|
+
});
|
17
|
+
|
18
|
+
describe('Realistic Form', () => {
|
19
|
+
it('Validates, resolves validation, submits values', async () => {
|
20
|
+
global.scrollTo = jest.fn();
|
21
|
+
const fullForm = (
|
22
|
+
<FormTestBase handleSubmit={handleSubmitMock}>
|
23
|
+
{({ Field }) => (
|
24
|
+
<>
|
25
|
+
<Field name="name" label="name" Component={StringInputGroup} />
|
26
|
+
<Field
|
27
|
+
name="nameWithIcon"
|
28
|
+
label="Name with Icon"
|
29
|
+
Component={StringInputGroup}
|
30
|
+
validate={validators.required}
|
31
|
+
/>
|
32
|
+
<StandardFormActions />
|
33
|
+
<Form.DisplayFormState />
|
34
|
+
</>
|
35
|
+
)}
|
36
|
+
</FormTestBase>
|
37
|
+
);
|
38
|
+
|
39
|
+
render(fullForm);
|
40
|
+
const nameInput = screen.getByLabelText('name');
|
41
|
+
const formSubmitButton = screen.getByRole('button', {
|
42
|
+
name: 'Submit',
|
43
|
+
});
|
44
|
+
//The form should start off with the submit button disabled
|
45
|
+
expect(formSubmitButton).toBeDisabled();
|
46
|
+
|
47
|
+
//Enter a name into the name input
|
48
|
+
user.click(nameInput);
|
49
|
+
user.type(nameInput, 'Travis Overmier');
|
50
|
+
expect(nameInput).toHaveValue('Travis Overmier');
|
51
|
+
|
52
|
+
//Submit should be enabled, click submit
|
53
|
+
expect(formSubmitButton).toBeEnabled();
|
54
|
+
user.click(formSubmitButton);
|
55
|
+
|
56
|
+
//Submit should disable while 'submitting' then re-enable
|
57
|
+
expect(formSubmitButton).toBeDisabled();
|
58
|
+
await waitFor(() => {
|
59
|
+
expect(formSubmitButton).toBeEnabled();
|
60
|
+
});
|
61
|
+
|
62
|
+
//Validation message should appear
|
63
|
+
const nameWithIconInput = screen.getByLabelText('Name with Icon');
|
64
|
+
expect(nameWithIconInput).toHaveErrorMessage('Required');
|
65
|
+
|
66
|
+
//Fill in field, error message goes away
|
67
|
+
user.type(nameWithIconInput, 'Kyle Joiner');
|
68
|
+
user.tab();
|
69
|
+
await waitFor(() => {
|
70
|
+
expect(nameWithIconInput).not.toHaveErrorMessage();
|
71
|
+
});
|
72
|
+
|
73
|
+
//Click the submit button
|
74
|
+
user.click(formSubmitButton);
|
75
|
+
await waitFor(() => {
|
76
|
+
expect(handleSubmitMock).toHaveBeenCalled();
|
77
|
+
expect(JSON.stringify(handleSubmitMock.mock.calls[0][0])).toBe(
|
78
|
+
`{"name":"Travis Overmier","nameWithIcon":"Kyle Joiner"}`
|
79
|
+
);
|
80
|
+
});
|
81
|
+
});
|
82
|
+
});
|
@@ -0,0 +1 @@
|
|
1
|
+
import '@testing-library/jest-dom/extend-expect';
|
@@ -1,27 +0,0 @@
|
|
1
|
-
/// <reference types="react" />
|
2
|
-
import '@testing-library/jest-dom/extend-expect';
|
3
|
-
import { FormBuilderProp } from '../';
|
4
|
-
interface FormTestBaseProps<TForm extends object> {
|
5
|
-
children: (formBuilder: FormBuilderProp<TForm>) => JSX.Element;
|
6
|
-
initialValues?: TForm;
|
7
|
-
}
|
8
|
-
export default function FormTestBase<TForm extends PersonDto>({ children, initialValues, }: FormTestBaseProps<TForm>): JSX.Element;
|
9
|
-
interface PersonDto {
|
10
|
-
name?: string | undefined;
|
11
|
-
nameWithIcon?: string | undefined;
|
12
|
-
numberOfArms?: number;
|
13
|
-
phoneNumber?: string;
|
14
|
-
yearlySalaryUSD?: number;
|
15
|
-
isCool?: boolean;
|
16
|
-
gradDate?: string;
|
17
|
-
favoriteDate?: string;
|
18
|
-
favoriteNumber?: number;
|
19
|
-
favoriteColor?: string;
|
20
|
-
favoriteColors?: string[];
|
21
|
-
favoriteNames?: string[];
|
22
|
-
allowLogin?: boolean;
|
23
|
-
userRoles?: number[];
|
24
|
-
profileImage?: any;
|
25
|
-
favoritePictures?: any[];
|
26
|
-
}
|
27
|
-
export {};
|
@@ -1,83 +0,0 @@
|
|
1
|
-
var __assign = (this && this.__assign) || function () {
|
2
|
-
__assign = Object.assign || function(t) {
|
3
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
4
|
-
s = arguments[i];
|
5
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
6
|
-
t[p] = s[p];
|
7
|
-
}
|
8
|
-
return t;
|
9
|
-
};
|
10
|
-
return __assign.apply(this, arguments);
|
11
|
-
};
|
12
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
13
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
14
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
15
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
16
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
17
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
18
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
19
|
-
});
|
20
|
-
};
|
21
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
22
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
23
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
24
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
25
|
-
function step(op) {
|
26
|
-
if (f) throw new TypeError("Generator is already executing.");
|
27
|
-
while (_) try {
|
28
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
29
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
30
|
-
switch (op[0]) {
|
31
|
-
case 0: case 1: t = op; break;
|
32
|
-
case 4: _.label++; return { value: op[1], done: false };
|
33
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
34
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
35
|
-
default:
|
36
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
37
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
38
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
39
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
40
|
-
if (t[2]) _.ops.pop();
|
41
|
-
_.trys.pop(); continue;
|
42
|
-
}
|
43
|
-
op = body.call(thisArg, _);
|
44
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
45
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
46
|
-
}
|
47
|
-
};
|
48
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
49
|
-
import '@testing-library/jest-dom/extend-expect';
|
50
|
-
import { HashRouter } from 'react-router-dom';
|
51
|
-
import { Form } from '../';
|
52
|
-
export default function FormTestBase(_a) {
|
53
|
-
var children = _a.children, initialValues = _a.initialValues;
|
54
|
-
return (_jsx(HashRouter, { children: _jsx(Form, __assign({ onSubmit: onSubmit, initialValues: initialValues }, { children: children })) }));
|
55
|
-
function onSubmit(data) {
|
56
|
-
return __awaiter(this, void 0, void 0, function () {
|
57
|
-
var isFormData, result, apiResult;
|
58
|
-
return __generator(this, function (_a) {
|
59
|
-
switch (_a.label) {
|
60
|
-
case 0:
|
61
|
-
isFormData = data instanceof FormData;
|
62
|
-
return [4 /*yield*/, fetch('/api/submit', {
|
63
|
-
body: isFormData ? data : JSON.stringify(data),
|
64
|
-
method: 'POST',
|
65
|
-
headers: {
|
66
|
-
'Content-Type': isFormData ? 'multipart/form-data' : 'application/json',
|
67
|
-
'X-Show-Errors': "Errors go here",
|
68
|
-
},
|
69
|
-
})];
|
70
|
-
case 1:
|
71
|
-
result = _a.sent();
|
72
|
-
return [4 /*yield*/, result.json()];
|
73
|
-
case 2:
|
74
|
-
apiResult = _a.sent();
|
75
|
-
if (!apiResult.hasErrors) {
|
76
|
-
alert('submitted');
|
77
|
-
}
|
78
|
-
return [2 /*return*/, apiResult];
|
79
|
-
}
|
80
|
-
});
|
81
|
-
});
|
82
|
-
}
|
83
|
-
}
|
package/es/__Tests__/index.d.ts
DELETED
package/es/__Tests__/index.js
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
/// <reference types="react" />
|
2
|
-
import '@testing-library/jest-dom/extend-expect';
|
3
|
-
import { FormBuilderProp } from '../';
|
4
|
-
interface FormTestBaseProps<TForm extends object> {
|
5
|
-
children: (formBuilder: FormBuilderProp<TForm>) => JSX.Element;
|
6
|
-
initialValues?: TForm;
|
7
|
-
}
|
8
|
-
export default function FormTestBase<TForm extends PersonDto>({ children, initialValues, }: FormTestBaseProps<TForm>): JSX.Element;
|
9
|
-
interface PersonDto {
|
10
|
-
name?: string | undefined;
|
11
|
-
nameWithIcon?: string | undefined;
|
12
|
-
numberOfArms?: number;
|
13
|
-
phoneNumber?: string;
|
14
|
-
yearlySalaryUSD?: number;
|
15
|
-
isCool?: boolean;
|
16
|
-
gradDate?: string;
|
17
|
-
favoriteDate?: string;
|
18
|
-
favoriteNumber?: number;
|
19
|
-
favoriteColor?: string;
|
20
|
-
favoriteColors?: string[];
|
21
|
-
favoriteNames?: string[];
|
22
|
-
allowLogin?: boolean;
|
23
|
-
userRoles?: number[];
|
24
|
-
profileImage?: any;
|
25
|
-
favoritePictures?: any[];
|
26
|
-
}
|
27
|
-
export {};
|
@@ -1,86 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
3
|
-
__assign = Object.assign || function(t) {
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
5
|
-
s = arguments[i];
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
7
|
-
t[p] = s[p];
|
8
|
-
}
|
9
|
-
return t;
|
10
|
-
};
|
11
|
-
return __assign.apply(this, arguments);
|
12
|
-
};
|
13
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
14
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
15
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
16
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
17
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
18
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
19
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
20
|
-
});
|
21
|
-
};
|
22
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
23
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
24
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
25
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
26
|
-
function step(op) {
|
27
|
-
if (f) throw new TypeError("Generator is already executing.");
|
28
|
-
while (_) try {
|
29
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
30
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
31
|
-
switch (op[0]) {
|
32
|
-
case 0: case 1: t = op; break;
|
33
|
-
case 4: _.label++; return { value: op[1], done: false };
|
34
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
35
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
36
|
-
default:
|
37
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
38
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
39
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
40
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
41
|
-
if (t[2]) _.ops.pop();
|
42
|
-
_.trys.pop(); continue;
|
43
|
-
}
|
44
|
-
op = body.call(thisArg, _);
|
45
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
46
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
47
|
-
}
|
48
|
-
};
|
49
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
50
|
-
var jsx_runtime_1 = require("react/jsx-runtime");
|
51
|
-
require("@testing-library/jest-dom/extend-expect");
|
52
|
-
var react_router_dom_1 = require("react-router-dom");
|
53
|
-
var __1 = require("../");
|
54
|
-
function FormTestBase(_a) {
|
55
|
-
var children = _a.children, initialValues = _a.initialValues;
|
56
|
-
return ((0, jsx_runtime_1.jsx)(react_router_dom_1.HashRouter, { children: (0, jsx_runtime_1.jsx)(__1.Form, __assign({ onSubmit: onSubmit, initialValues: initialValues }, { children: children })) }));
|
57
|
-
function onSubmit(data) {
|
58
|
-
return __awaiter(this, void 0, void 0, function () {
|
59
|
-
var isFormData, result, apiResult;
|
60
|
-
return __generator(this, function (_a) {
|
61
|
-
switch (_a.label) {
|
62
|
-
case 0:
|
63
|
-
isFormData = data instanceof FormData;
|
64
|
-
return [4 /*yield*/, fetch('/api/submit', {
|
65
|
-
body: isFormData ? data : JSON.stringify(data),
|
66
|
-
method: 'POST',
|
67
|
-
headers: {
|
68
|
-
'Content-Type': isFormData ? 'multipart/form-data' : 'application/json',
|
69
|
-
'X-Show-Errors': "Errors go here",
|
70
|
-
},
|
71
|
-
})];
|
72
|
-
case 1:
|
73
|
-
result = _a.sent();
|
74
|
-
return [4 /*yield*/, result.json()];
|
75
|
-
case 2:
|
76
|
-
apiResult = _a.sent();
|
77
|
-
if (!apiResult.hasErrors) {
|
78
|
-
alert('submitted');
|
79
|
-
}
|
80
|
-
return [2 /*return*/, apiResult];
|
81
|
-
}
|
82
|
-
});
|
83
|
-
});
|
84
|
-
}
|
85
|
-
}
|
86
|
-
exports.default = FormTestBase;
|
package/lib/__Tests__/index.d.ts
DELETED
package/lib/__Tests__/index.js
DELETED
@@ -1,8 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
-
};
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
-
exports.FormTestBase = void 0;
|
7
|
-
var FormTestBase_1 = __importDefault(require("./FormTestBase"));
|
8
|
-
exports.FormTestBase = FormTestBase_1.default;
|