envoc-form 4.0.1-10 → 4.0.1-11
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/es/AddressInput/AddressInput.d.ts +5 -5
- package/es/DatePicker/DatePickerGroup.d.ts +1 -1
- package/es/DatePicker/DatePickerGroup.js +9 -4
- package/es/DatePicker/StringDateOnlyPickerGroup.d.ts +1 -1
- package/es/DatePicker/StringDatePickerGroup.d.ts +1 -1
- package/es/Field/Field.d.ts +2 -2
- package/es/FieldArray/FieldArray.d.ts +2 -2
- package/es/FieldArray/FieldArray.js +2 -2
- package/es/File/FileGroup.d.ts +1 -1
- package/es/File/FileGroup.js +1 -1
- package/es/File/FileList.d.ts +2 -2
- package/es/Form/FormBasedPreventNavigation.js +31 -14
- package/es/Input/IconInputGroup.d.ts +1 -1
- package/es/Input/IconInputGroup.js +2 -1
- package/es/Input/InputGroup.d.ts +2 -2
- package/es/Input/InputGroup.js +2 -2
- package/es/Input/MoneyInputGroup.d.ts +1 -1
- package/es/Input/NumberInputGroup.d.ts +1 -1
- package/es/Input/StringInputGroup.d.ts +1 -1
- package/es/Input/StringInputGroup.js +2 -1
- package/es/Normalization/normalizers.d.ts +2 -2
- package/es/Select/BooleanSelectGroup.d.ts +1 -1
- package/es/Select/NumberSelectGroup.d.ts +2 -2
- package/es/Select/SelectGroup.d.ts +1 -1
- package/es/Select/SelectGroup.js +1 -1
- package/es/SubmitFormButton.d.ts +1 -1
- package/es/TextArea/TextAreaGroup.d.ts +1 -1
- package/es/TextArea/TextAreaGroup.js +3 -2
- package/es/Validation/validators.d.ts +8 -8
- package/es/Validation/validators.js +3 -0
- package/es/__Tests__/FormTestBase.d.ts +1 -1
- package/es/__Tests__/FormTestBase.js +1 -1
- package/es/index.d.ts +4 -4
- package/lib/AddressInput/AddressInput.d.ts +5 -5
- package/lib/DatePicker/DatePickerGroup.d.ts +1 -1
- package/lib/DatePicker/DatePickerGroup.js +9 -4
- package/lib/DatePicker/StringDateOnlyPickerGroup.d.ts +1 -1
- package/lib/DatePicker/StringDatePickerGroup.d.ts +1 -1
- package/lib/Field/Field.d.ts +2 -2
- package/lib/FieldArray/FieldArray.d.ts +2 -2
- package/lib/FieldArray/FieldArray.js +2 -2
- package/lib/File/FileGroup.d.ts +1 -1
- package/lib/File/FileGroup.js +1 -1
- package/lib/File/FileList.d.ts +2 -2
- package/lib/Form/FormBasedPreventNavigation.js +31 -14
- package/lib/Input/IconInputGroup.d.ts +1 -1
- package/lib/Input/IconInputGroup.js +2 -1
- package/lib/Input/InputGroup.d.ts +2 -2
- package/lib/Input/InputGroup.js +2 -2
- package/lib/Input/MoneyInputGroup.d.ts +1 -1
- package/lib/Input/NumberInputGroup.d.ts +1 -1
- package/lib/Input/StringInputGroup.d.ts +1 -1
- package/lib/Input/StringInputGroup.js +2 -1
- package/lib/Normalization/normalizers.d.ts +2 -2
- package/lib/Select/BooleanSelectGroup.d.ts +1 -1
- package/lib/Select/NumberSelectGroup.d.ts +2 -2
- package/lib/Select/SelectGroup.d.ts +1 -1
- package/lib/Select/SelectGroup.js +1 -1
- package/lib/SubmitFormButton.d.ts +1 -1
- package/lib/TextArea/TextAreaGroup.d.ts +1 -1
- package/lib/TextArea/TextAreaGroup.js +3 -2
- package/lib/Validation/validators.d.ts +8 -8
- package/lib/Validation/validators.js +3 -0
- package/lib/__Tests__/FormTestBase.d.ts +1 -1
- package/lib/__Tests__/FormTestBase.js +2 -2
- package/lib/index.d.ts +4 -4
- package/package.json +2 -2
- package/src/AddressInput/AddressInput.tsx +5 -5
- package/src/DatePicker/DatePickerGroup.tsx +8 -4
- package/src/DatePicker/StringDateOnlyPickerGroup.tsx +2 -2
- package/src/DatePicker/StringDatePickerGroup.tsx +1 -1
- package/src/Field/Field.tsx +2 -2
- package/src/FieldArray/FieldArray.tsx +5 -5
- package/src/File/FileGroup.tsx +2 -2
- package/src/File/FileList.tsx +2 -2
- package/src/Form/FormBasedPreventNavigation.tsx +34 -18
- package/src/Input/IconInputGroup.tsx +2 -2
- package/src/Input/InputGroup.tsx +8 -4
- package/src/Input/MoneyInputGroup.tsx +1 -1
- package/src/Input/NumberInputGroup.tsx +1 -1
- package/src/Input/StringInputGroup.tsx +2 -2
- package/src/Normalization/normalizers.ts +2 -2
- package/src/Select/BooleanSelectGroup.tsx +1 -1
- package/src/Select/NumberSelectGroup.tsx +2 -2
- package/src/Select/SelectGroup.tsx +2 -2
- package/src/SubmitFormButton.tsx +2 -1
- package/src/TextArea/TextAreaGroup.tsx +3 -3
- package/src/Validation/validators.ts +16 -12
- package/src/__Tests__/FormTestBase.tsx +2 -2
- package/src/index.ts +4 -4
package/src/Input/InputGroup.tsx
CHANGED
@@ -1,18 +1,22 @@
|
|
1
1
|
import React, { ChangeEventHandler, 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 InputGroupProps<TValue>
|
8
8
|
extends InjectedFieldProps<TValue>,
|
9
9
|
Omit<
|
10
10
|
React.HTMLProps<HTMLInputElement>,
|
11
|
-
keyof InjectedFieldProps<any>
|
11
|
+
| keyof InjectedFieldProps<any>
|
12
|
+
| 'children'
|
13
|
+
| 'className'
|
14
|
+
| 'label'
|
15
|
+
| 'value'
|
12
16
|
>,
|
13
17
|
Omit<GroupProps, keyof InjectedFieldProps<any> | 'children'> {
|
14
18
|
onChange: ChangeEventHandler<HTMLInputElement>;
|
15
|
-
value: string | number;
|
19
|
+
value: string | number | null | undefined;
|
16
20
|
icon?: React.ReactNode;
|
17
21
|
}
|
18
22
|
|
@@ -49,7 +53,7 @@ function InputGroup<TValue>(
|
|
49
53
|
<input
|
50
54
|
{...input}
|
51
55
|
{...rest}
|
52
|
-
value={value}
|
56
|
+
value={value ?? ''}
|
53
57
|
onChange={onChange}
|
54
58
|
ref={ref}
|
55
59
|
className={classNames(
|
@@ -5,7 +5,7 @@ import { FormDefaults } from '../FormDefaults';
|
|
5
5
|
|
6
6
|
export interface MoneyInputGroupProps
|
7
7
|
extends Omit<
|
8
|
-
InputGroupProps<number | undefined>,
|
8
|
+
InputGroupProps<number | undefined | null>,
|
9
9
|
'onChange' | 'type' | 'value'
|
10
10
|
> {
|
11
11
|
parseFunc?: typeof parseInt | typeof parseFloat;
|
@@ -5,7 +5,7 @@ import { FormDefaults } from '../FormDefaults';
|
|
5
5
|
|
6
6
|
export interface NumberInputGroupProps
|
7
7
|
extends Omit<
|
8
|
-
InputGroupProps<number | undefined>,
|
8
|
+
InputGroupProps<number | undefined | null>,
|
9
9
|
'onChange' | 'type' | 'value'
|
10
10
|
> {
|
11
11
|
parseFunc?: typeof parseInt | typeof parseFloat;
|
@@ -5,7 +5,7 @@ import { FormDefaults } from '../FormDefaults';
|
|
5
5
|
|
6
6
|
export interface StringInputGroupProps
|
7
7
|
extends Omit<
|
8
|
-
InputGroupProps<string | undefined>,
|
8
|
+
InputGroupProps<string | undefined | null>,
|
9
9
|
'onChange' | 'type' | 'value'
|
10
10
|
> {
|
11
11
|
type?:
|
@@ -33,7 +33,7 @@ function StringInputGroup(
|
|
33
33
|
className,
|
34
34
|
FormDefaults.cssClassPrefix + 'string-group'
|
35
35
|
)}
|
36
|
-
value={input.value
|
36
|
+
value={input.value ?? ''}
|
37
37
|
onChange={(e) => {
|
38
38
|
if (!e.target.value) {
|
39
39
|
input.onChange(undefined);
|
@@ -1,4 +1,4 @@
|
|
1
|
-
export const phoneNumber = (value: string | undefined) => {
|
1
|
+
export const phoneNumber = (value: string | undefined | null) => {
|
2
2
|
if (!value) {
|
3
3
|
return undefined;
|
4
4
|
}
|
@@ -30,7 +30,7 @@ export const phoneNumber = (value: string | undefined) => {
|
|
30
30
|
return onlyNums;
|
31
31
|
};
|
32
32
|
|
33
|
-
export const zipCode = (value: string | undefined) => {
|
33
|
+
export const zipCode = (value: string | undefined | null) => {
|
34
34
|
if (!value) {
|
35
35
|
return undefined;
|
36
36
|
}
|
@@ -13,7 +13,7 @@ const booleanOptions: SelectOption<boolean>[] = [
|
|
13
13
|
];
|
14
14
|
|
15
15
|
export interface BooleanSelectGroupProps
|
16
|
-
extends Omit<SelectGroupPropsHelper<boolean>, 'options'> {
|
16
|
+
extends Omit<SelectGroupPropsHelper<boolean | undefined | null>, 'options'> {
|
17
17
|
options?: SelectOption<boolean>[];
|
18
18
|
}
|
19
19
|
export function BooleanSelectGroup(props: BooleanSelectGroupProps) {
|
@@ -2,13 +2,13 @@ import SelectGroup from './SelectGroup';
|
|
2
2
|
import { SelectGroupPropsHelper } from './SelectGroupPropsHelper';
|
3
3
|
|
4
4
|
export interface MultiNumberSelectGroupProps
|
5
|
-
extends SelectGroupPropsHelper<number[]> {}
|
5
|
+
extends SelectGroupPropsHelper<number[] | undefined | null> {}
|
6
6
|
export function MultiNumberSelectGroup(props: MultiNumberSelectGroupProps) {
|
7
7
|
return <SelectGroup multiple={true} {...props} />;
|
8
8
|
}
|
9
9
|
|
10
10
|
export interface SingleNumberSelectGroupProps
|
11
|
-
extends SelectGroupPropsHelper<number> {}
|
11
|
+
extends SelectGroupPropsHelper<number | undefined | null> {}
|
12
12
|
export function SingleNumberSelectGroup(props: SingleNumberSelectGroupProps) {
|
13
13
|
return <SelectGroup multiple={false} {...props} />;
|
14
14
|
}
|
@@ -1,8 +1,8 @@
|
|
1
1
|
import { default as ReactSelect } from 'react-select';
|
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 SelectOption<TValue> {
|
8
8
|
value: (TValue extends Array<infer P> ? P : TValue) | undefined;
|
@@ -23,7 +23,7 @@ interface OptionsUseServiceResult<TValue> {
|
|
23
23
|
}
|
24
24
|
|
25
25
|
export interface SelectGroupProps<TValue>
|
26
|
-
extends InjectedFieldProps<TValue | undefined>,
|
26
|
+
extends InjectedFieldProps<TValue | undefined | null>,
|
27
27
|
Omit<GroupProps, 'input' | 'meta' | 'children'> {
|
28
28
|
// allows for "useService" or other handles to control the data - including cache
|
29
29
|
// TODO: do we still want a version of select that has a "url" or maybe a promise func or something?
|
package/src/SubmitFormButton.tsx
CHANGED
@@ -8,6 +8,7 @@ export interface SubmitFormButtonProps
|
|
8
8
|
allowPristineSubmit?: boolean;
|
9
9
|
children?: React.ReactNode;
|
10
10
|
}
|
11
|
+
|
11
12
|
function SubmitFormButton(
|
12
13
|
{
|
13
14
|
allowPristineSubmit,
|
@@ -47,4 +48,4 @@ function SubmitFormButton(
|
|
47
48
|
|
48
49
|
export default React.forwardRef(
|
49
50
|
SubmitFormButton
|
50
|
-
) as React.
|
51
|
+
) 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'
|
@@ -45,7 +45,7 @@ function TextAreaGroup(
|
|
45
45
|
<textarea
|
46
46
|
{...input}
|
47
47
|
{...rest}
|
48
|
-
value={input.value}
|
48
|
+
value={input.value ?? ''}
|
49
49
|
onChange={(val) => input.onChange(val.target.value)}
|
50
50
|
ref={ref}
|
51
51
|
className={classNames(
|
@@ -10,12 +10,13 @@ export const required = (value: any) =>
|
|
10
10
|
: 'Required';
|
11
11
|
|
12
12
|
//asserts that the value is a certain number of characters. numbers are coerced to a string
|
13
|
-
export const length =
|
14
|
-
|
15
|
-
|
16
|
-
}
|
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,35 +26,35 @@ 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
|
-
export const zipCode = (value: string | undefined) => {
|
57
|
+
export const zipCode = (value: string | undefined | null) => {
|
57
58
|
return value && !/^[0-9]{5}(?:-[0-9]{4})?$/.test(value)
|
58
59
|
? 'Invalid ZIP Code'
|
59
60
|
: undefined;
|
@@ -73,7 +74,10 @@ export const any =
|
|
73
74
|
);
|
74
75
|
};
|
75
76
|
|
76
|
-
function getLengthOfValue(value: string | number | undefined) {
|
77
|
+
function getLengthOfValue(value: string | number | undefined | null) {
|
78
|
+
if (value === null) {
|
79
|
+
return 0;
|
80
|
+
}
|
77
81
|
switch (typeof value) {
|
78
82
|
case 'undefined':
|
79
83
|
return 0;
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import '@testing-library/jest-dom/extend-expect';
|
2
2
|
import { HashRouter } from 'react-router-dom';
|
3
|
-
import {
|
4
|
-
import {
|
3
|
+
import { Form, FormBuilderProp } from '../';
|
4
|
+
import { ValidatedApiResult } from '../Validation/ValidatedApiResult';
|
5
5
|
|
6
6
|
interface FormTestBaseProps<TForm extends object> {
|
7
7
|
children: (formBuilder: FormBuilderProp<TForm>) => JSX.Element;
|
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';
|