envoc-form 4.0.1-10 → 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 +15 -5
- 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 +6 -1
- package/es/DatePicker/DatePickerGroup.js +14 -4
- package/es/DatePicker/StringDateOnlyPickerGroup.d.ts +6 -1
- package/es/DatePicker/StringDateOnlyPickerGroup.js +5 -0
- package/es/DatePicker/StringDatePickerGroup.d.ts +6 -1
- package/es/DatePicker/StringDatePickerGroup.js +5 -0
- package/es/Field/Field.d.ts +8 -2
- 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 +11 -2
- package/es/FieldArray/FieldArray.js +7 -2
- package/es/File/FileGroup.d.ts +3 -1
- package/es/File/FileGroup.js +2 -1
- package/es/File/FileList.d.ts +2 -2
- 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 -45
- 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 +4 -1
- package/es/Input/IconInputGroup.js +3 -1
- package/es/Input/InputGroup.d.ts +3 -3
- package/es/Input/InputGroup.js +3 -3
- package/es/Input/MoneyInputGroup.d.ts +3 -1
- package/es/Input/MoneyInputGroup.js +1 -0
- package/es/Input/NumberInputGroup.d.ts +3 -1
- package/es/Input/NumberInputGroup.js +1 -0
- package/es/Input/StringInputGroup.d.ts +2 -1
- package/es/Input/StringInputGroup.js +3 -1
- package/es/Normalization/normalizers.d.ts +4 -2
- package/es/Normalization/normalizers.js +2 -0
- package/es/Select/BooleanSelectGroup.d.ts +2 -1
- package/es/Select/BooleanSelectGroup.js +1 -0
- package/es/Select/NumberSelectGroup.d.ts +4 -2
- package/es/Select/NumberSelectGroup.js +2 -0
- package/es/Select/SelectGroup.d.ts +7 -1
- package/es/Select/SelectGroup.js +2 -1
- 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 +4 -1
- package/es/SubmitFormButton.js +1 -0
- package/es/TextArea/TextAreaGroup.d.ts +2 -1
- package/es/TextArea/TextAreaGroup.js +4 -3
- package/es/Validation/validators.d.ts +11 -8
- package/es/Validation/validators.js +6 -2
- package/es/index.d.ts +4 -4
- package/es/setupTests.d.ts +1 -0
- package/es/setupTests.js +1 -0
- package/lib/AddressInput/AddressInput.d.ts +15 -5
- 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 +6 -1
- package/lib/DatePicker/DatePickerGroup.js +14 -4
- package/lib/DatePicker/StringDateOnlyPickerGroup.d.ts +6 -1
- package/lib/DatePicker/StringDateOnlyPickerGroup.js +5 -0
- package/lib/DatePicker/StringDatePickerGroup.d.ts +6 -1
- package/lib/DatePicker/StringDatePickerGroup.js +5 -0
- package/lib/Field/Field.d.ts +8 -2
- 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 +11 -2
- package/lib/FieldArray/FieldArray.js +7 -2
- package/lib/File/FileGroup.d.ts +3 -1
- package/lib/File/FileGroup.js +2 -1
- package/lib/File/FileList.d.ts +2 -2
- 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 -43
- 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 +4 -1
- package/lib/Input/IconInputGroup.js +3 -1
- package/lib/Input/InputGroup.d.ts +3 -3
- package/lib/Input/InputGroup.js +3 -3
- package/lib/Input/MoneyInputGroup.d.ts +3 -1
- package/lib/Input/MoneyInputGroup.js +1 -0
- package/lib/Input/NumberInputGroup.d.ts +3 -1
- package/lib/Input/NumberInputGroup.js +1 -0
- package/lib/Input/StringInputGroup.d.ts +2 -1
- package/lib/Input/StringInputGroup.js +3 -1
- package/lib/Normalization/normalizers.d.ts +4 -2
- package/lib/Normalization/normalizers.js +2 -0
- package/lib/Select/BooleanSelectGroup.d.ts +2 -1
- package/lib/Select/BooleanSelectGroup.js +1 -0
- package/lib/Select/NumberSelectGroup.d.ts +4 -2
- package/lib/Select/NumberSelectGroup.js +2 -0
- package/lib/Select/SelectGroup.d.ts +7 -1
- package/lib/Select/SelectGroup.js +2 -1
- 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 +4 -1
- package/lib/SubmitFormButton.js +1 -0
- package/lib/TextArea/TextAreaGroup.d.ts +2 -1
- package/lib/TextArea/TextAreaGroup.js +4 -3
- package/lib/Validation/validators.d.ts +11 -8
- package/lib/Validation/validators.js +6 -2
- package/lib/index.d.ts +4 -4
- package/lib/setupTests.d.ts +1 -0
- package/lib/setupTests.js +3 -0
- package/package.json +9 -6
- package/src/AddressInput/AddressInput.tsx +15 -5
- 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 +13 -6
- package/src/DatePicker/StringDateOnlyPickerGroup.tsx +7 -2
- package/src/DatePicker/StringDatePickerGroup.tsx +7 -1
- package/src/Field/Field.tsx +8 -3
- 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 +14 -5
- package/src/File/FileGroup.tsx +4 -2
- package/src/File/FileList.tsx +2 -2
- package/src/Form/FocusError.tsx +3 -0
- package/src/Form/Form.tsx +6 -0
- package/src/Form/FormBasedPreventNavigation.tsx +28 -46
- 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 +5 -2
- package/src/Input/InputGroup.tsx +11 -5
- package/src/Input/MoneyInputGroup.tsx +3 -1
- package/src/Input/NumberInputGroup.tsx +3 -1
- package/src/Input/StringInputGroup.tsx +3 -2
- 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 +4 -2
- package/src/Select/BooleanSelectGroup.tsx +2 -1
- package/src/Select/NumberSelectGroup.tsx +4 -2
- package/src/Select/SelectGroup.tsx +8 -2
- package/src/Select/StringSelectGroup.tsx +2 -0
- package/src/StandardFormActions.tsx +5 -0
- package/src/SubmitFormButton.tsx +5 -1
- package/src/TextArea/TextAreaGroup.tsx +4 -4
- package/src/Validation/validators.ts +19 -14
- package/src/__Tests__/FormTestBase.tsx +9 -8
- package/src/__Tests__/RealisticForm.test.tsx +82 -0
- package/src/index.ts +4 -4
- 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
package/src/SubmitFormButton.tsx
CHANGED
@@ -5,9 +5,12 @@ 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
|
}
|
13
|
+
|
11
14
|
function SubmitFormButton(
|
12
15
|
{
|
13
16
|
allowPristineSubmit,
|
@@ -45,6 +48,7 @@ function SubmitFormButton(
|
|
45
48
|
);
|
46
49
|
}
|
47
50
|
|
51
|
+
/** Generic submit button for forms. */
|
48
52
|
export default React.forwardRef(
|
49
53
|
SubmitFormButton
|
50
|
-
) as React.
|
54
|
+
) as React.FunctionComponent<SubmitFormButtonProps>;
|
@@ -1,11 +1,11 @@
|
|
1
1
|
import React, { LegacyRef } from 'react';
|
2
2
|
import classNames from 'classnames';
|
3
3
|
import { InjectedFieldProps } from '../Field/InjectedFieldProps';
|
4
|
-
import Group, { GroupProps } from '../Group';
|
5
4
|
import { FormDefaults } from '../FormDefaults';
|
5
|
+
import Group, { GroupProps } from '../Group';
|
6
6
|
|
7
7
|
export interface TextAreaGroupProps
|
8
|
-
extends InjectedFieldProps<string | undefined>,
|
8
|
+
extends InjectedFieldProps<string | undefined | null>,
|
9
9
|
Omit<
|
10
10
|
React.HTMLProps<HTMLTextAreaElement>,
|
11
11
|
keyof InjectedFieldProps<any> | 'children' | 'className' | 'label'
|
@@ -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,
|
@@ -45,7 +44,7 @@ function TextAreaGroup(
|
|
45
44
|
<textarea
|
46
45
|
{...input}
|
47
46
|
{...rest}
|
48
|
-
value={input.value}
|
47
|
+
value={input.value ?? ''}
|
49
48
|
onChange={(val) => input.onChange(val.target.value)}
|
50
49
|
ref={ref}
|
51
50
|
className={classNames(
|
@@ -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,13 +9,14 @@ export const required = (value: any) =>
|
|
9
9
|
? undefined
|
10
10
|
: 'Required';
|
11
11
|
|
12
|
-
|
13
|
-
export const length =
|
14
|
-
|
15
|
-
|
16
|
-
}
|
12
|
+
/** Asserts that the value is a certain number of characters. numbers are coerced to a string */
|
13
|
+
export const length =
|
14
|
+
(len: number) => (value: string | number | undefined | null) => {
|
15
|
+
const hasError = getLengthOfValue(value) !== len;
|
16
|
+
return !hasError ? undefined : `Length must be ${len}`;
|
17
|
+
};
|
17
18
|
|
18
|
-
export const integer = (val: string | number | undefined) => {
|
19
|
+
export const integer = (val: string | number | undefined | null) => {
|
19
20
|
if (!val) {
|
20
21
|
return undefined;
|
21
22
|
}
|
@@ -25,41 +26,42 @@ export const integer = (val: string | number | undefined) => {
|
|
25
26
|
};
|
26
27
|
|
27
28
|
export const maxLength =
|
28
|
-
(len: number) => (value: string | number | undefined) => {
|
29
|
+
(len: number) => (value: string | number | undefined | null) => {
|
29
30
|
const hasError = getLengthOfValue(value) > len;
|
30
31
|
return !hasError ? undefined : `Maximum length ${len} exceeded`;
|
31
32
|
};
|
32
33
|
|
33
34
|
export const maxCount =
|
34
|
-
(count: number) => (value: { isDeleted?: boolean }[] | undefined) => {
|
35
|
+
(count: number) => (value: { isDeleted?: boolean }[] | undefined | null) => {
|
35
36
|
const hasError =
|
36
37
|
!!value && value.filter((x) => !x.isDeleted).length > count;
|
37
38
|
return !hasError ? undefined : `Should not have more than ${count}`;
|
38
39
|
};
|
39
40
|
|
40
41
|
export const minCount =
|
41
|
-
(count: number) => (value: { isDeleted?: boolean }[] | undefined) => {
|
42
|
+
(count: number) => (value: { isDeleted?: boolean }[] | undefined | null) => {
|
42
43
|
const hasError = !value || value.filter((x) => !x.isDeleted).length < count;
|
43
44
|
return !hasError ? undefined : `Should have at least ${count}`;
|
44
45
|
};
|
45
46
|
|
46
|
-
export const maxValue = (max: number) => (value: number | undefined) => {
|
47
|
+
export const maxValue = (max: number) => (value: number | undefined | null) => {
|
47
48
|
const hasError = !!value && value > max;
|
48
49
|
return !hasError ? undefined : `Maximum value ${max} exceeded`;
|
49
50
|
};
|
50
51
|
|
51
|
-
export const minValue = (min: number) => (value: number | undefined) => {
|
52
|
+
export const minValue = (min: number) => (value: number | undefined | null) => {
|
52
53
|
const hasError = !value || value < min;
|
53
54
|
return !hasError ? undefined : `Minimum value ${min} not met`;
|
54
55
|
};
|
55
56
|
|
56
|
-
|
57
|
+
/** Validate for a ZIP Code. Accepts formats: ##### and #####-#### */
|
58
|
+
export const zipCode = (value: string | undefined | null) => {
|
57
59
|
return value && !/^[0-9]{5}(?:-[0-9]{4})?$/.test(value)
|
58
60
|
? 'Invalid ZIP Code'
|
59
61
|
: undefined;
|
60
62
|
};
|
61
63
|
|
62
|
-
|
64
|
+
/** One of the validators provided must be true. */
|
63
65
|
export const any =
|
64
66
|
<TValue>(validatorList: ValidationFunction<TValue>[]) =>
|
65
67
|
(value: TValue) => {
|
@@ -73,7 +75,10 @@ export const any =
|
|
73
75
|
);
|
74
76
|
};
|
75
77
|
|
76
|
-
function getLengthOfValue(value: string | number | undefined) {
|
78
|
+
function getLengthOfValue(value: string | number | undefined | null) {
|
79
|
+
if (value === null) {
|
80
|
+
return 0;
|
81
|
+
}
|
77
82
|
switch (typeof value) {
|
78
83
|
case 'undefined':
|
79
84
|
return 0;
|
@@ -1,28 +1,29 @@
|
|
1
|
-
import '@testing-library/jest-dom/extend-expect';
|
2
1
|
import { HashRouter } from 'react-router-dom';
|
3
|
-
import {
|
4
|
-
import {
|
2
|
+
import { Form, FormBuilderProp } from '../';
|
3
|
+
import { ValidatedApiResult } from '../Validation/ValidatedApiResult';
|
5
4
|
|
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
|
+
});
|
package/src/index.ts
CHANGED
@@ -16,7 +16,7 @@ export type { ConfirmDeleteFormProps } from './ConfirmDeleteForm/ConfirmDeleteFo
|
|
16
16
|
|
17
17
|
// Date
|
18
18
|
export { default as DatePickerGroup } from './DatePicker/DatePickerGroup';
|
19
|
-
export type { DatePickerGroupProps
|
19
|
+
export type { DatePickerGroupProps } from './DatePicker/DatePickerGroup';
|
20
20
|
export { convertToTimeZoneInsensitiveISOString } from './DatePicker/DatePickerGroup';
|
21
21
|
|
22
22
|
export type { DatePickerHelper } from './DatePicker/DatePickerHelper';
|
@@ -68,17 +68,17 @@ export type {
|
|
68
68
|
} from './Form/ServerErrorContext';
|
69
69
|
|
70
70
|
export { default as FormActions } from './FormActions';
|
71
|
-
export type { FormActionsProps
|
71
|
+
export type { FormActionsProps } from './FormActions';
|
72
72
|
|
73
73
|
export { default as StandardFormActions } from './StandardFormActions';
|
74
|
-
export type { StandardFormActionsProps
|
74
|
+
export type { StandardFormActionsProps } from './StandardFormActions';
|
75
75
|
|
76
76
|
// FormDefaults
|
77
77
|
export { FormDefaults } from './FormDefaults';
|
78
78
|
|
79
79
|
// Input
|
80
80
|
export { default as Group } from './Group';
|
81
|
-
export type { GroupProps
|
81
|
+
export type { GroupProps } from './Group';
|
82
82
|
|
83
83
|
export { default as IconInputGroup } from './Input/IconInputGroup';
|
84
84
|
export type { IconInputGroupProps } from './Input/IconInputGroup';
|
@@ -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 '../../src';
|
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 '../../src';
|
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 '../../src';
|
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 src_1 = require("../../src");
|
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)(src_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;
|