envoc-form 4.0.1-8 → 4.1.0

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.
Files changed (204) hide show
  1. package/README.md +5117 -12
  2. package/es/AddressInput/AddressInput.d.ts +15 -5
  3. package/es/AddressInput/AddressInput.js +10 -0
  4. package/es/ConfirmBaseForm/ConfirmBaseForm.d.ts +14 -0
  5. package/es/ConfirmBaseForm/ConfirmBaseForm.js +6 -0
  6. package/es/ConfirmDeleteForm/ConfirmDeleteForm.d.ts +13 -0
  7. package/es/ConfirmDeleteForm/ConfirmDeleteForm.js +5 -0
  8. package/es/DatePicker/DatePickerGroup.d.ts +7 -2
  9. package/es/DatePicker/DatePickerGroup.js +16 -6
  10. package/es/DatePicker/StringDateOnlyPickerGroup.d.ts +6 -1
  11. package/es/DatePicker/StringDateOnlyPickerGroup.js +5 -0
  12. package/es/DatePicker/StringDatePickerGroup.d.ts +6 -1
  13. package/es/DatePicker/StringDatePickerGroup.js +5 -0
  14. package/es/Field/Field.d.ts +9 -3
  15. package/es/Field/Field.js +9 -4
  16. package/es/Field/FieldErrorScrollTarget.d.ts +1 -0
  17. package/es/Field/FieldErrorScrollTarget.js +1 -0
  18. package/es/Field/StandAloneInput.d.ts +4 -0
  19. package/es/Field/StandAloneInput.js +1 -0
  20. package/es/Field/useStandardField.d.ts +6 -0
  21. package/es/Field/useStandardField.js +8 -9
  22. package/es/FieldArray/FieldArray.d.ts +11 -2
  23. package/es/FieldArray/FieldArray.js +7 -2
  24. package/es/File/FileGroup.d.ts +3 -1
  25. package/es/File/FileGroup.js +4 -3
  26. package/es/File/FileList.d.ts +2 -2
  27. package/es/Form/FocusError.d.ts +2 -0
  28. package/es/Form/FocusError.js +1 -0
  29. package/es/Form/Form.d.ts +6 -0
  30. package/es/Form/Form.js +1 -0
  31. package/es/Form/FormBasedPreventNavigation.d.ts +3 -1
  32. package/es/Form/FormBasedPreventNavigation.js +12 -45
  33. package/es/Form/LegacyFormBasedPreventNavigation.d.ts +17 -0
  34. package/es/Form/LegacyFormBasedPreventNavigation.js +69 -0
  35. package/es/Form/NewFormBasedPreventNavigation.d.ts +14 -0
  36. package/es/Form/NewFormBasedPreventNavigation.js +39 -0
  37. package/es/Form/ServerErrorContext.d.ts +1 -0
  38. package/es/Form/ServerErrorContext.js +1 -0
  39. package/es/FormActions.d.ts +6 -0
  40. package/es/FormActions.js +1 -0
  41. package/es/FormDefaults.d.ts +1 -0
  42. package/es/FormDefaults.js +1 -0
  43. package/es/Group.d.ts +7 -4
  44. package/es/Group.js +4 -3
  45. package/es/Input/IconInputGroup.d.ts +4 -1
  46. package/es/Input/IconInputGroup.js +3 -1
  47. package/es/Input/InputGroup.d.ts +4 -4
  48. package/es/Input/InputGroup.js +4 -4
  49. package/es/Input/MoneyInputGroup.d.ts +3 -1
  50. package/es/Input/MoneyInputGroup.js +1 -0
  51. package/es/Input/NumberInputGroup.d.ts +3 -1
  52. package/es/Input/NumberInputGroup.js +1 -0
  53. package/es/Input/StringInputGroup.d.ts +2 -1
  54. package/es/Input/StringInputGroup.js +3 -1
  55. package/es/Normalization/normalizers.d.ts +4 -2
  56. package/es/Normalization/normalizers.js +2 -0
  57. package/es/Select/BooleanSelectGroup.d.ts +2 -1
  58. package/es/Select/BooleanSelectGroup.js +1 -0
  59. package/es/Select/NumberSelectGroup.d.ts +4 -2
  60. package/es/Select/NumberSelectGroup.js +2 -0
  61. package/es/Select/SelectGroup.d.ts +8 -2
  62. package/es/Select/SelectGroup.js +5 -4
  63. package/es/Select/StringSelectGroup.d.ts +2 -0
  64. package/es/Select/StringSelectGroup.js +2 -0
  65. package/es/StandardFormActions.d.ts +5 -0
  66. package/es/StandardFormActions.js +1 -0
  67. package/es/SubmitFormButton.d.ts +4 -1
  68. package/es/SubmitFormButton.js +1 -0
  69. package/es/TextArea/TextAreaGroup.d.ts +2 -1
  70. package/es/TextArea/TextAreaGroup.js +5 -4
  71. package/es/Validation/validators.d.ts +11 -8
  72. package/es/Validation/validators.js +6 -2
  73. package/es/index.d.ts +4 -4
  74. package/es/setupTests.d.ts +1 -0
  75. package/es/setupTests.js +1 -0
  76. package/lib/AddressInput/AddressInput.d.ts +15 -5
  77. package/lib/AddressInput/AddressInput.js +10 -0
  78. package/lib/ConfirmBaseForm/ConfirmBaseForm.d.ts +14 -0
  79. package/lib/ConfirmBaseForm/ConfirmBaseForm.js +6 -0
  80. package/lib/ConfirmDeleteForm/ConfirmDeleteForm.d.ts +13 -0
  81. package/lib/ConfirmDeleteForm/ConfirmDeleteForm.js +5 -0
  82. package/lib/DatePicker/DatePickerGroup.d.ts +7 -2
  83. package/lib/DatePicker/DatePickerGroup.js +16 -6
  84. package/lib/DatePicker/StringDateOnlyPickerGroup.d.ts +6 -1
  85. package/lib/DatePicker/StringDateOnlyPickerGroup.js +5 -0
  86. package/lib/DatePicker/StringDatePickerGroup.d.ts +6 -1
  87. package/lib/DatePicker/StringDatePickerGroup.js +5 -0
  88. package/lib/Field/Field.d.ts +9 -3
  89. package/lib/Field/Field.js +9 -4
  90. package/lib/Field/FieldErrorScrollTarget.d.ts +1 -0
  91. package/lib/Field/FieldErrorScrollTarget.js +1 -0
  92. package/lib/Field/StandAloneInput.d.ts +4 -0
  93. package/lib/Field/StandAloneInput.js +1 -0
  94. package/lib/Field/useStandardField.d.ts +6 -0
  95. package/lib/Field/useStandardField.js +8 -9
  96. package/lib/FieldArray/FieldArray.d.ts +11 -2
  97. package/lib/FieldArray/FieldArray.js +7 -2
  98. package/lib/File/FileGroup.d.ts +3 -1
  99. package/lib/File/FileGroup.js +4 -3
  100. package/lib/File/FileList.d.ts +2 -2
  101. package/lib/Form/FocusError.d.ts +2 -0
  102. package/lib/Form/FocusError.js +1 -0
  103. package/lib/Form/Form.d.ts +6 -0
  104. package/lib/Form/Form.js +1 -0
  105. package/lib/Form/FormBasedPreventNavigation.d.ts +3 -1
  106. package/lib/Form/FormBasedPreventNavigation.js +13 -43
  107. package/lib/Form/LegacyFormBasedPreventNavigation.d.ts +17 -0
  108. package/lib/Form/LegacyFormBasedPreventNavigation.js +72 -0
  109. package/lib/Form/NewFormBasedPreventNavigation.d.ts +14 -0
  110. package/lib/Form/NewFormBasedPreventNavigation.js +42 -0
  111. package/lib/Form/ServerErrorContext.d.ts +1 -0
  112. package/lib/Form/ServerErrorContext.js +1 -0
  113. package/lib/FormActions.d.ts +6 -0
  114. package/lib/FormActions.js +1 -0
  115. package/lib/FormDefaults.d.ts +1 -0
  116. package/lib/FormDefaults.js +1 -0
  117. package/lib/Group.d.ts +7 -4
  118. package/lib/Group.js +4 -3
  119. package/lib/Input/IconInputGroup.d.ts +4 -1
  120. package/lib/Input/IconInputGroup.js +3 -1
  121. package/lib/Input/InputGroup.d.ts +4 -4
  122. package/lib/Input/InputGroup.js +4 -4
  123. package/lib/Input/MoneyInputGroup.d.ts +3 -1
  124. package/lib/Input/MoneyInputGroup.js +1 -0
  125. package/lib/Input/NumberInputGroup.d.ts +3 -1
  126. package/lib/Input/NumberInputGroup.js +1 -0
  127. package/lib/Input/StringInputGroup.d.ts +2 -1
  128. package/lib/Input/StringInputGroup.js +3 -1
  129. package/lib/Normalization/normalizers.d.ts +4 -2
  130. package/lib/Normalization/normalizers.js +2 -0
  131. package/lib/Select/BooleanSelectGroup.d.ts +2 -1
  132. package/lib/Select/BooleanSelectGroup.js +1 -0
  133. package/lib/Select/NumberSelectGroup.d.ts +4 -2
  134. package/lib/Select/NumberSelectGroup.js +2 -0
  135. package/lib/Select/SelectGroup.d.ts +8 -2
  136. package/lib/Select/SelectGroup.js +5 -4
  137. package/lib/Select/StringSelectGroup.d.ts +2 -0
  138. package/lib/Select/StringSelectGroup.js +2 -0
  139. package/lib/StandardFormActions.d.ts +5 -0
  140. package/lib/StandardFormActions.js +1 -0
  141. package/lib/SubmitFormButton.d.ts +4 -1
  142. package/lib/SubmitFormButton.js +1 -0
  143. package/lib/TextArea/TextAreaGroup.d.ts +2 -1
  144. package/lib/TextArea/TextAreaGroup.js +5 -4
  145. package/lib/Validation/validators.d.ts +11 -8
  146. package/lib/Validation/validators.js +6 -2
  147. package/lib/index.d.ts +4 -4
  148. package/lib/setupTests.d.ts +1 -0
  149. package/lib/setupTests.js +3 -0
  150. package/package.json +9 -6
  151. package/src/AddressInput/AddressInput.tsx +15 -5
  152. package/src/AddressInput/__snapshots__/AddressInput.test.tsx.snap +8 -4
  153. package/src/ConfirmBaseForm/ConfirmBaseForm.tsx +14 -0
  154. package/src/ConfirmDeleteForm/ConfirmDeleteForm.tsx +13 -0
  155. package/src/DatePicker/DatePicker.test.tsx +1 -1
  156. package/src/DatePicker/DatePickerGroup.tsx +18 -7
  157. package/src/DatePicker/StringDateOnlyPickerGroup.tsx +7 -2
  158. package/src/DatePicker/StringDatePickerGroup.tsx +7 -1
  159. package/src/Field/Field.tsx +20 -7
  160. package/src/Field/FieldErrorScrollTarget.tsx +1 -0
  161. package/src/Field/StandAloneInput.tsx +4 -0
  162. package/src/Field/useStandardField.ts +13 -9
  163. package/src/FieldArray/FieldArray.tsx +14 -5
  164. package/src/File/FileGroup.tsx +9 -3
  165. package/src/File/FileList.tsx +2 -2
  166. package/src/Form/FocusError.tsx +3 -0
  167. package/src/Form/Form.tsx +6 -0
  168. package/src/Form/FormBasedPreventNavigation.tsx +28 -46
  169. package/src/Form/LegacyFormBasedPreventNavigation.tsx +77 -0
  170. package/src/Form/NewFormBasedPreventNavigation.tsx +59 -0
  171. package/src/Form/ServerErrorContext.ts +1 -0
  172. package/src/FormActions.tsx +7 -0
  173. package/src/FormDefaults.ts +1 -0
  174. package/src/Group.tsx +12 -4
  175. package/src/Input/IconInputGroup.tsx +5 -2
  176. package/src/Input/InputGroup.tsx +13 -5
  177. package/src/Input/MoneyInputGroup.tsx +3 -1
  178. package/src/Input/NumberInputGroup.tsx +3 -1
  179. package/src/Input/StringInputGroup.tsx +3 -2
  180. package/src/Input/__Tests__/__snapshots__/IconInputGroup.test.tsx.snap +1 -0
  181. package/src/Input/__Tests__/__snapshots__/MoneyInputGroup.test.tsx.snap +1 -0
  182. package/src/Input/__Tests__/__snapshots__/NumberInputGroup.test.tsx.snap +1 -0
  183. package/src/Input/__Tests__/__snapshots__/StringInputGroup.test.tsx.snap +1 -0
  184. package/src/Normalization/normalizers.ts +4 -2
  185. package/src/Select/BooleanSelectGroup.tsx +2 -1
  186. package/src/Select/NumberSelectGroup.tsx +4 -2
  187. package/src/Select/SelectGroup.tsx +13 -2
  188. package/src/Select/StringSelectGroup.tsx +2 -0
  189. package/src/StandardFormActions.tsx +5 -0
  190. package/src/SubmitFormButton.tsx +5 -1
  191. package/src/TextArea/TextAreaGroup.tsx +6 -4
  192. package/src/Validation/validators.ts +19 -14
  193. package/src/__Tests__/FormTestBase.tsx +9 -8
  194. package/src/__Tests__/RealisticForm.test.tsx +82 -0
  195. package/src/index.ts +4 -4
  196. package/src/setupTests.ts +1 -0
  197. package/es/__Tests__/FormTestBase.d.ts +0 -27
  198. package/es/__Tests__/FormTestBase.js +0 -83
  199. package/es/__Tests__/index.d.ts +0 -2
  200. package/es/__Tests__/index.js +0 -2
  201. package/lib/__Tests__/FormTestBase.d.ts +0 -27
  202. package/lib/__Tests__/FormTestBase.js +0 -86
  203. package/lib/__Tests__/index.d.ts +0 -2
  204. package/lib/__Tests__/index.js +0 -8
@@ -1,7 +1,10 @@
1
1
  import React from 'react';
2
2
  export interface SubmitFormButtonProps extends Omit<React.HTMLProps<HTMLButtonElement>, 'type'> {
3
+ /** Allow the form to be submitted without any changes. By default this is not allowed. */
3
4
  allowPristineSubmit?: boolean;
5
+ /** Text to display on the button. Default text is 'Submit'. */
4
6
  children?: React.ReactNode;
5
7
  }
6
- declare const _default: React.ComponentType<SubmitFormButtonProps>;
8
+ declare const _default: React.FunctionComponent<SubmitFormButtonProps>;
9
+ /** Generic submit button for forms. */
7
10
  export default _default;
@@ -36,4 +36,5 @@ function SubmitFormButton(_a, ref) {
36
36
  ? "You haven't made any changes"
37
37
  : '', className: classNames(FormDefaults.cssClassPrefix + 'submit-form-button', className) }, { children: children || 'Submit' })));
38
38
  }
39
+ /** Generic submit button for forms. */
39
40
  export default React.forwardRef(SubmitFormButton);
@@ -1,8 +1,9 @@
1
1
  import React from 'react';
2
2
  import { InjectedFieldProps } from '../Field/InjectedFieldProps';
3
3
  import { GroupProps } from '../Group';
4
- export interface TextAreaGroupProps extends InjectedFieldProps<string | undefined>, Omit<React.HTMLProps<HTMLTextAreaElement>, keyof InjectedFieldProps<any> | 'children' | 'className' | 'label'>, Omit<GroupProps, keyof InjectedFieldProps<any> | 'children'> {
4
+ export interface TextAreaGroupProps extends InjectedFieldProps<string | undefined | null>, Omit<React.HTMLProps<HTMLTextAreaElement>, keyof InjectedFieldProps<any> | 'children' | 'className' | 'label'>, Omit<GroupProps, keyof InjectedFieldProps<any> | 'children'> {
5
5
  icon?: React.ReactNode;
6
6
  }
7
+ /** Generic controlled `<textarea/>` wrapped by a `<Group/>` */
7
8
  declare const TextAreaGroupWithRef: React.ComponentType<TextAreaGroupProps>;
8
9
  export default TextAreaGroupWithRef;
@@ -23,12 +23,13 @@ var __rest = (this && this.__rest) || function (s, e) {
23
23
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
24
24
  import React from 'react';
25
25
  import classNames from 'classnames';
26
- import Group from '../Group';
27
26
  import { FormDefaults } from '../FormDefaults';
28
- /** generic controlled <textarea/> wrapped by a Group */
27
+ import Group from '../Group';
29
28
  function TextAreaGroup(_a, ref) {
30
- var input = _a.input, meta = _a.meta, label = _a.label, helpText = _a.helpText, className = _a.className, disabled = _a.disabled, icon = _a.icon, rest = __rest(_a, ["input", "meta", "label", "helpText", "className", "disabled", "icon"]);
31
- return (_jsxs(Group, __assign({ input: input, meta: meta, disabled: disabled, label: label, helpText: helpText, className: classNames(className, FormDefaults.cssClassPrefix + 'text-area-group') }, { children: [icon, _jsx("textarea", __assign({}, input, rest, { value: input.value, onChange: function (val) { return input.onChange(val.target.value); }, ref: ref, className: classNames(className, FormDefaults.cssClassPrefix + 'text-area-group') }))] })));
29
+ var _b;
30
+ var input = _a.input, meta = _a.meta, label = _a.label, helpText = _a.helpText, className = _a.className, required = _a.required, disabled = _a.disabled, icon = _a.icon, rest = __rest(_a, ["input", "meta", "label", "helpText", "className", "required", "disabled", "icon"]);
31
+ return (_jsxs(Group, __assign({ input: input, meta: meta, required: required, disabled: disabled, label: label, helpText: helpText, className: classNames(className, FormDefaults.cssClassPrefix + 'text-area-group') }, { children: [icon, _jsx("textarea", __assign({}, input, rest, { value: (_b = input.value) !== null && _b !== void 0 ? _b : '', onChange: function (val) { return input.onChange(val.target.value); }, ref: ref, className: classNames(className, FormDefaults.cssClassPrefix + 'text-area-group') }))] })));
32
32
  }
33
+ /** Generic controlled `<textarea/>` wrapped by a `<Group/>` */
33
34
  var TextAreaGroupWithRef = React.forwardRef(TextAreaGroup);
34
35
  export default TextAreaGroupWithRef;
@@ -1,15 +1,18 @@
1
1
  import { ValidationFunction } from './ValidationFunction';
2
2
  export declare const required: (value: any) => "Required" | undefined;
3
- export declare const length: (len: number) => (value: string | number | undefined) => string | undefined;
4
- export declare const integer: (val: string | number | undefined) => "Must be a whole number" | undefined;
5
- export declare const maxLength: (len: number) => (value: string | number | undefined) => string | undefined;
3
+ /** Asserts that the value is a certain number of characters. numbers are coerced to a string */
4
+ export declare const length: (len: number) => (value: string | number | undefined | null) => string | undefined;
5
+ export declare const integer: (val: string | number | undefined | null) => "Must be a whole number" | undefined;
6
+ export declare const maxLength: (len: number) => (value: string | number | undefined | null) => string | undefined;
6
7
  export declare const maxCount: (count: number) => (value: {
7
8
  isDeleted?: boolean;
8
- }[] | undefined) => string | undefined;
9
+ }[] | undefined | null) => string | undefined;
9
10
  export declare const minCount: (count: number) => (value: {
10
11
  isDeleted?: boolean;
11
- }[] | undefined) => string | undefined;
12
- export declare const maxValue: (max: number) => (value: number | undefined) => string | undefined;
13
- export declare const minValue: (min: number) => (value: number | undefined) => string | undefined;
14
- export declare const zipCode: (value: string | undefined) => "Invalid ZIP Code" | undefined;
12
+ }[] | undefined | null) => string | undefined;
13
+ export declare const maxValue: (max: number) => (value: number | undefined | null) => string | undefined;
14
+ export declare const minValue: (min: number) => (value: number | undefined | null) => string | undefined;
15
+ /** Validate for a ZIP Code. Accepts formats: ##### and #####-#### */
16
+ export declare const zipCode: (value: string | undefined | null) => "Invalid ZIP Code" | undefined;
17
+ /** One of the validators provided must be true. */
15
18
  export declare const any: <TValue>(validatorList: ValidationFunction<TValue>[]) => (value: TValue) => string | undefined;
@@ -7,7 +7,7 @@ export var required = function (value) {
7
7
  ? undefined
8
8
  : 'Required';
9
9
  };
10
- //asserts that the value is a certain number of characters. numbers are coerced to a string
10
+ /** Asserts that the value is a certain number of characters. numbers are coerced to a string */
11
11
  export var length = function (len) { return function (value) {
12
12
  var hasError = getLengthOfValue(value) !== len;
13
13
  return !hasError ? undefined : "Length must be ".concat(len);
@@ -40,12 +40,13 @@ export var minValue = function (min) { return function (value) {
40
40
  var hasError = !value || value < min;
41
41
  return !hasError ? undefined : "Minimum value ".concat(min, " not met");
42
42
  }; };
43
+ /** Validate for a ZIP Code. Accepts formats: ##### and #####-#### */
43
44
  export var zipCode = function (value) {
44
45
  return value && !/^[0-9]{5}(?:-[0-9]{4})?$/.test(value)
45
46
  ? 'Invalid ZIP Code'
46
47
  : undefined;
47
48
  };
48
- //one of the validators provided must be true
49
+ /** One of the validators provided must be true. */
49
50
  export var any = function (validatorList) {
50
51
  return function (value) {
51
52
  if (validatorList.length === 0 || !value) {
@@ -55,6 +56,9 @@ export var any = function (validatorList) {
55
56
  };
56
57
  };
57
58
  function getLengthOfValue(value) {
59
+ if (value === null) {
60
+ return 0;
61
+ }
58
62
  switch (typeof value) {
59
63
  case 'undefined':
60
64
  return 0;
package/es/index.d.ts CHANGED
@@ -7,7 +7,7 @@ export type { ConfirmBaseFormProps } from './ConfirmBaseForm/ConfirmBaseForm';
7
7
  export { default as ConfirmDeleteForm } from './ConfirmDeleteForm/ConfirmDeleteForm';
8
8
  export type { ConfirmDeleteFormProps } from './ConfirmDeleteForm/ConfirmDeleteForm';
9
9
  export { default as DatePickerGroup } from './DatePicker/DatePickerGroup';
10
- export type { DatePickerGroupProps as DatePickerGroupProps } from './DatePicker/DatePickerGroup';
10
+ export type { DatePickerGroupProps } from './DatePicker/DatePickerGroup';
11
11
  export { convertToTimeZoneInsensitiveISOString } from './DatePicker/DatePickerGroup';
12
12
  export type { DatePickerHelper } from './DatePicker/DatePickerHelper';
13
13
  export { default as StringDatePickerGroup } from './DatePicker/StringDatePickerGroup';
@@ -34,12 +34,12 @@ export type { FormBuilderProp, FormProps } from './Form/Form';
34
34
  export { ServerErrorContext } from './Form/ServerErrorContext';
35
35
  export type { ServerErrorContextProps, ServerErrors, } from './Form/ServerErrorContext';
36
36
  export { default as FormActions } from './FormActions';
37
- export type { FormActionsProps as FormActionsProps } from './FormActions';
37
+ export type { FormActionsProps } from './FormActions';
38
38
  export { default as StandardFormActions } from './StandardFormActions';
39
- export type { StandardFormActionsProps as StandardFormActionsProps } from './StandardFormActions';
39
+ export type { StandardFormActionsProps } from './StandardFormActions';
40
40
  export { FormDefaults } from './FormDefaults';
41
41
  export { default as Group } from './Group';
42
- export type { GroupProps as GroupProps } from './Group';
42
+ export type { GroupProps } from './Group';
43
43
  export { default as IconInputGroup } from './Input/IconInputGroup';
44
44
  export type { IconInputGroupProps } from './Input/IconInputGroup';
45
45
  export { default as InputGroup } from './Input/InputGroup';
@@ -0,0 +1 @@
1
+ import '@testing-library/jest-dom/extend-expect';
@@ -0,0 +1 @@
1
+ import '@testing-library/jest-dom/extend-expect';
@@ -5,11 +5,21 @@ export interface AddressInputProps {
5
5
  name: string;
6
6
  }
7
7
  interface AddressDto {
8
- address1?: string;
9
- address2?: string;
10
- zipCode?: string;
11
- city?: string;
12
- state?: string;
8
+ address1?: string | null;
9
+ address2?: string | null;
10
+ zipCode?: string | null;
11
+ city?: string | null;
12
+ state?: string | null;
13
13
  }
14
+ /**
15
+ * Collection of `<Field/>`s for inputting an address. Includes:
16
+ * ```txt
17
+ * Address 1
18
+ * Address 2
19
+ * City
20
+ * State
21
+ * Zip
22
+ * ```
23
+ */
14
24
  export default function AddressInput({ fieldBuilder: { Field }, name, }: AddressInputProps): JSX.Element;
15
25
  export {};
@@ -20,6 +20,16 @@ var __1 = require("../");
20
20
  var FieldSection_1 = __importDefault(require("../Field/FieldSection"));
21
21
  var normalizers_1 = require("../Normalization/normalizers");
22
22
  var validators_1 = require("../Validation/validators");
23
+ /**
24
+ * Collection of `<Field/>`s for inputting an address. Includes:
25
+ * ```txt
26
+ * Address 1
27
+ * Address 2
28
+ * City
29
+ * State
30
+ * Zip
31
+ * ```
32
+ */
23
33
  function AddressInput(_a) {
24
34
  var Field = _a.fieldBuilder.Field, name = _a.name;
25
35
  return ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: (0, jsx_runtime_1.jsxs)(FieldSection_1.default, __assign({ name: name }, { children: [(0, jsx_runtime_1.jsx)(Field, { name: "address1", placeholder: "Address, Line 1", label: "Address 1", Component: __1.StringInputGroup, validate: validators_1.required }), (0, jsx_runtime_1.jsx)(Field, { name: "address2", placeholder: "Address, Line 2", label: "Address 2", Component: __1.StringInputGroup }), (0, jsx_runtime_1.jsx)(Field, { name: "city", placeholder: "City", label: "City", Component: __1.StringInputGroup, validate: validators_1.required }), (0, jsx_runtime_1.jsx)(Field, { name: "state", placeholder: "State", label: "State", Component: __1.SingleStringSelectGroup, options: UsStates_1.default, validate: validators_1.required }), (0, jsx_runtime_1.jsx)(Field, { name: "zipCode", placeholder: "Zip", label: "Zip", Component: __1.StringInputGroup, normalize: normalizers_1.zipCode, validate: [validators_1.required, validators_1.zipCode] })] })) }));
@@ -1,12 +1,26 @@
1
1
  import React, { MouseEventHandler } from 'react';
2
2
  import { useAxiosRequestProps } from 'envoc-request';
3
3
  export interface ConfirmBaseFormProps {
4
+ /** Function to run when cancel button is clicked. */
4
5
  handleCancel?: MouseEventHandler<HTMLButtonElement>;
6
+ /** Axios request upon confirmation */
5
7
  request: useAxiosRequestProps;
6
8
  style?: React.CSSProperties;
9
+ /** `<h3/>` title text on top of the form. */
7
10
  title?: string;
11
+ /** Custom confirm button text.
12
+ * @defaultValue `Confirm`
13
+ */
8
14
  confirmButtonText?: string;
15
+ /** CSS class for the buttons. */
9
16
  confirmButtonClass?: string;
17
+ /** Any components to be rendered in between the title and the buttons. */
10
18
  children?: React.ReactNode;
11
19
  }
20
+ /**
21
+ * Confimation dialog. Navigates to a different route to allow the user to either confirm or cancel an action.
22
+ * Commonly used for confirming delete and archive.
23
+ *
24
+ * See `<ConfirmDeleteForm/>` if the confirmation is specifically for deletion.
25
+ */
12
26
  export default function ConfirmBaseForm({ handleCancel, request, style, title, confirmButtonText, confirmButtonClass, children, ...props }: ConfirmBaseFormProps): JSX.Element;
@@ -30,6 +30,12 @@ var classnames_1 = __importDefault(require("classnames"));
30
30
  var envoc_request_1 = require("envoc-request");
31
31
  var FormDefaults_1 = require("../FormDefaults");
32
32
  // TODO: ask about how we should use 'children'
33
+ /**
34
+ * Confimation dialog. Navigates to a different route to allow the user to either confirm or cancel an action.
35
+ * Commonly used for confirming delete and archive.
36
+ *
37
+ * See `<ConfirmDeleteForm/>` if the confirmation is specifically for deletion.
38
+ */
33
39
  function ConfirmBaseForm(_a) {
34
40
  var handleCancel = _a.handleCancel, request = _a.request, style = _a.style, title = _a.title, confirmButtonText = _a.confirmButtonText, confirmButtonClass = _a.confirmButtonClass, children = _a.children, props = __rest(_a, ["handleCancel", "request", "style", "title", "confirmButtonText", "confirmButtonClass", "children"]);
35
41
  var webRequest = (0, envoc_request_1.useAxiosRequest)(Object.assign({}, request, { autoExecute: false }));
@@ -1,11 +1,24 @@
1
1
  import React from 'react';
2
2
  import { ConfirmBaseFormProps } from '../ConfirmBaseForm/ConfirmBaseForm';
3
3
  export interface ConfirmDeleteFormProps extends Pick<ConfirmBaseFormProps, 'style'> {
4
+ /** Url to navigate to on success. */
4
5
  successUrl?: string;
6
+ /** Form name (key) to apply the confirmation on. */
5
7
  form: string;
8
+ /** Custom message to display.
9
+ * @defaultValue `Are you sure you want to delete this?`
10
+ */
6
11
  title?: string;
12
+ /** Custom function when the axios request succeeds. */
7
13
  handleComplete?: Function;
14
+ /** Custom function when the axios request fails. */
8
15
  handleError?: Function;
16
+ /** Any components to be rendered in between the title and the buttons. */
9
17
  children?: React.ReactNode;
10
18
  }
19
+ /**
20
+ * Deletion confirmation. Navigates to a different route to allow the user to either confirm or cancel an action.
21
+ *
22
+ * Wraps `<ConfirmBaseForm/>`.
23
+ */
11
24
  export default function ConfirmDeleteForm({ successUrl, form, title, handleComplete, handleError, children, ...props }: ConfirmDeleteFormProps): JSX.Element;
@@ -30,6 +30,11 @@ var react_router_dom_1 = require("react-router-dom");
30
30
  var react_toastify_1 = require("react-toastify");
31
31
  var ConfirmBaseForm_1 = __importDefault(require("../ConfirmBaseForm/ConfirmBaseForm"));
32
32
  var FormDefaults_1 = require("../FormDefaults");
33
+ /**
34
+ * Deletion confirmation. Navigates to a different route to allow the user to either confirm or cancel an action.
35
+ *
36
+ * Wraps `<ConfirmBaseForm/>`.
37
+ */
33
38
  function ConfirmDeleteForm(_a) {
34
39
  var successUrl = _a.successUrl, form = _a.form, title = _a.title, handleComplete = _a.handleComplete, handleError = _a.handleError, children = _a.children, props = __rest(_a, ["successUrl", "form", "title", "handleComplete", "handleError", "children"]);
35
40
  var navigate = (0, react_router_dom_1.useNavigate)();
@@ -2,8 +2,13 @@
2
2
  import { DatePickerProps } from 'react-date-picker/dist/entry.nostyle';
3
3
  import { InjectedFieldProps } from '../Field/InjectedFieldProps';
4
4
  import { GroupProps } from '../Group';
5
- export interface DatePickerGroupProps<T> extends InjectedFieldProps<T | undefined>, Omit<DatePickerProps, keyof InjectedFieldProps<T> | 'name' | 'value' | 'className'>, Omit<GroupProps, keyof InjectedFieldProps<T> | 'children'> {
5
+ export interface DatePickerGroupProps<T> extends InjectedFieldProps<T | undefined | null>, Omit<DatePickerProps, keyof InjectedFieldProps<T> | 'name' | 'value' | 'className'>, Omit<GroupProps, keyof InjectedFieldProps<T> | 'children'> {
6
6
  convert: (arg: Date) => T;
7
7
  }
8
- export default function DatePickerGroup<T>({ input, meta, label, helpText, className, disabled, convert, ...rest }: DatePickerGroupProps<T>): JSX.Element;
8
+ /**
9
+ * Field for inputting dates. Uses `<Group/>` and `<DatePicker/>`.
10
+ *
11
+ * Uses [react-date-picker](https://www.npmjs.com/package/react-date-picker)
12
+ */
13
+ export default function DatePickerGroup<T>({ input, meta, label, helpText, className, required, disabled, convert, ...rest }: DatePickerGroupProps<T>): JSX.Element;
9
14
  export declare function convertToTimeZoneInsensitiveISOString(date: Date): string;
@@ -33,18 +33,28 @@ var classnames_1 = __importDefault(require("classnames"));
33
33
  var parseISO_1 = __importDefault(require("date-fns/parseISO"));
34
34
  var FormDefaults_1 = require("../FormDefaults");
35
35
  var Group_1 = __importDefault(require("../Group"));
36
+ /**
37
+ * Field for inputting dates. Uses `<Group/>` and `<DatePicker/>`.
38
+ *
39
+ * Uses [react-date-picker](https://www.npmjs.com/package/react-date-picker)
40
+ */
36
41
  function DatePickerGroup(_a) {
37
- var input = _a.input, meta = _a.meta, label = _a.label, helpText = _a.helpText, className = _a.className, disabled = _a.disabled, convert = _a.convert, rest = __rest(_a, ["input", "meta", "label", "helpText", "className", "disabled", "convert"]);
42
+ var input = _a.input, meta = _a.meta, label = _a.label, helpText = _a.helpText, className = _a.className, required = _a.required, disabled = _a.disabled, convert = _a.convert, rest = __rest(_a, ["input", "meta", "label", "helpText", "className", "required", "disabled", "convert"]);
38
43
  var _b = (0, react_1.useState)(null), displayDate = _b[0], setDisplayDate = _b[1];
39
44
  (0, react_1.useEffect)(function () {
40
- if (input.value != null) {
41
- setDisplayDate(new Date("".concat(input.value, "T00:00:00.000")));
42
- }
43
- else {
45
+ if (!input.value) {
44
46
  setDisplayDate(null);
45
47
  }
48
+ else if (typeof input.value === 'string') {
49
+ if (input.value.indexOf('T') === -1) {
50
+ setDisplayDate(new Date("".concat(input.value, "T00:00:00.000")));
51
+ }
52
+ else {
53
+ setDisplayDate(new Date(input.value));
54
+ }
55
+ }
46
56
  }, [setDisplayDate, input.value]);
47
- return ((0, jsx_runtime_1.jsx)(Group_1.default, __assign({ input: input, meta: meta, label: label, helpText: helpText, className: (0, classnames_1.default)(className, FormDefaults_1.FormDefaults.cssClassPrefix + 'date-picker'), disabled: disabled }, { children: (0, jsx_runtime_1.jsx)(entry_nostyle_1.default, __assign({}, rest, { className: (0, classnames_1.default)(FormDefaults_1.FormDefaults.cssClassPrefix + 'date-picker', className), value: displayDate, onChange: handleChange })) })));
57
+ return ((0, jsx_runtime_1.jsx)(Group_1.default, __assign({ input: input, meta: meta, label: label, helpText: helpText, className: (0, classnames_1.default)(className, FormDefaults_1.FormDefaults.cssClassPrefix + 'date-picker'), required: required, disabled: disabled }, { children: (0, jsx_runtime_1.jsx)(entry_nostyle_1.default, __assign({}, rest, { className: (0, classnames_1.default)(FormDefaults_1.FormDefaults.cssClassPrefix + 'date-picker', className), value: displayDate, onChange: handleChange })) })));
48
58
  function handleChange(e) {
49
59
  var onChange = input.onChange;
50
60
  if (onChange === null) {
@@ -1,5 +1,10 @@
1
1
  /// <reference types="react" />
2
2
  import { DatePickerHelper } from './DatePickerHelper';
3
- export interface StringDateOnlyPickerGroupProps extends DatePickerHelper<string | undefined> {
3
+ export interface StringDateOnlyPickerGroupProps extends DatePickerHelper<string | undefined | null> {
4
4
  }
5
+ /**
6
+ * Date picker input that consumes and outputs as a date only string in ISO format `YYYY-MM-DD`.
7
+ *
8
+ * Default display to the user is in `MM/DD/YYYY` format.
9
+ */
5
10
  export default function StringDatePickerGroup(props: StringDateOnlyPickerGroupProps): JSX.Element;
@@ -16,6 +16,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  var jsx_runtime_1 = require("react/jsx-runtime");
18
18
  var DatePickerGroup_1 = __importDefault(require("./DatePickerGroup"));
19
+ /**
20
+ * Date picker input that consumes and outputs as a date only string in ISO format `YYYY-MM-DD`.
21
+ *
22
+ * Default display to the user is in `MM/DD/YYYY` format.
23
+ */
19
24
  function StringDatePickerGroup(props) {
20
25
  return (0, jsx_runtime_1.jsx)(DatePickerGroup_1.default, __assign({}, props, { convert: convertToDateOnly }));
21
26
  }
@@ -1,5 +1,10 @@
1
1
  /// <reference types="react" />
2
2
  import { DatePickerHelper } from './DatePickerHelper';
3
- export interface StringDatePickerGroupProps extends DatePickerHelper<string | undefined> {
3
+ export interface StringDatePickerGroupProps extends DatePickerHelper<string | undefined | null> {
4
4
  }
5
+ /**
6
+ * Date picker input that consumes and outputs as a date only string in ISO format `YYYY-MM-DDTHH:mm:ss.sssZ` or `±YYYYYY-MM-DDTHH:mm:ss.sssZ`
7
+ *
8
+ * If you need `YYYY-MM-DD` format use `<StringDateOnlyPickerGroup/>`.
9
+ */
5
10
  export default function StringDatePickerGroup(props: StringDatePickerGroupProps): JSX.Element;
@@ -16,6 +16,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  var jsx_runtime_1 = require("react/jsx-runtime");
18
18
  var DatePickerGroup_1 = __importDefault(require("./DatePickerGroup"));
19
+ /**
20
+ * Date picker input that consumes and outputs as a date only string in ISO format `YYYY-MM-DDTHH:mm:ss.sssZ` or `±YYYYYY-MM-DDTHH:mm:ss.sssZ`
21
+ *
22
+ * If you need `YYYY-MM-DD` format use `<StringDateOnlyPickerGroup/>`.
23
+ */
19
24
  function StringDatePickerGroup(props) {
20
25
  return (0, jsx_runtime_1.jsx)(DatePickerGroup_1.default, __assign({}, props, { convert: convertToDateOnly }));
21
26
  }
@@ -2,21 +2,27 @@ import { ComponentProps, ElementType, LegacyRef } from 'react';
2
2
  import { InjectedFieldProps } from './InjectedFieldProps';
3
3
  import { NormalizationFunction } from '../Normalization/NormalizationFunction';
4
4
  import { ValidationFunction } from '../Validation/ValidationFunction';
5
- export declare type RenderComponent<TValue, TRenderComponent extends ElementType> = Partial<ComponentProps<TRenderComponent>> extends Partial<InjectedFieldProps<TValue>> ? TRenderComponent : never;
6
- export declare type RenderComponentProps<TValue, TRenderComponent extends ElementType> = Partial<ComponentProps<TRenderComponent>> extends Partial<InjectedFieldProps<TValue>> ? ComponentProps<TRenderComponent> : never;
5
+ export declare type RenderComponent<TValue, TRenderComponent extends ElementType> = Partial<ComponentProps<TRenderComponent>> extends Partial<InjectedFieldProps<TValue | undefined | null>> ? TRenderComponent : never;
6
+ export declare type RenderComponentProps<TValue, TRenderComponent extends ElementType> = Partial<ComponentProps<TRenderComponent>> extends Partial<InjectedFieldProps<TValue | undefined | null>> ? ComponentProps<TRenderComponent> : never;
7
7
  /** A specific Field instance to be rendered by the given TRenderComponent or by whatever default is reasonable */
8
8
  export declare type FieldProps<TForm extends object, TProp extends keyof TForm, TRenderComponent extends ElementType> = {
9
+ /** Name of the field. Used on submission. */
9
10
  name: TProp;
11
+ /** Component to be rendered. Usually this is a type of input group e.g. `<StringInputGroup/>` */
10
12
  Component: RenderComponent<TForm[TProp], TRenderComponent>;
13
+ /** Id of the field. */
11
14
  id?: string;
15
+ /** Whether the field should be disabled. */
12
16
  disabled?: boolean;
17
+ /** Client side validation functions */
13
18
  validate?: ValidationFunction<TForm[TProp]> | ValidationFunction<TForm[TProp]>[];
19
+ /** Function to modify the field value without making the form dirty. (e.g. phone number) */
14
20
  normalize?: NormalizationFunction<TForm[TProp]>;
15
21
  } & Omit<RenderComponentProps<TForm[TProp], TRenderComponent>, keyof InjectedFieldProps<TForm[TProp]>>;
16
22
  /**
17
23
  * Renders whatever Component is passed - injecting the formik values needed to finish wiring up that individual field.
18
24
  * Should no Component be used then the default will be provided by the default lookup based on typeof(TForm[TProp])
19
25
  */
20
- declare function Field<TForm extends object, TProp extends keyof TForm, TRenderComponent extends ElementType>({ name, Component, id, normalize, validate, disabled, ...rest }: FieldProps<TForm, TProp, TRenderComponent>, ref: LegacyRef<any>): JSX.Element;
26
+ declare function Field<TForm extends object, TProp extends keyof TForm, TRenderComponent extends ElementType>({ name, Component, id, disabled, validate, normalize, ...rest }: FieldProps<TForm, TProp, TRenderComponent>, ref: LegacyRef<any>): JSX.Element;
21
27
  declare const _default: typeof Field;
22
28
  export default _default;
@@ -29,22 +29,27 @@ var jsx_runtime_1 = require("react/jsx-runtime");
29
29
  var react_1 = __importDefault(require("react"));
30
30
  var FieldNameContext_1 = require("./FieldNameContext");
31
31
  var useStandardField_1 = __importDefault(require("./useStandardField"));
32
+ var validators_1 = require("../Validation/validators");
32
33
  /**
33
34
  * Renders whatever Component is passed - injecting the formik values needed to finish wiring up that individual field.
34
35
  * Should no Component be used then the default will be provided by the default lookup based on typeof(TForm[TProp])
35
36
  */
36
37
  function Field(_a, ref) {
37
- var name = _a.name, Component = _a.Component, id = _a.id, normalize = _a.normalize, validate = _a.validate, disabled = _a.disabled, rest = __rest(_a, ["name", "Component", "id", "normalize", "validate", "disabled"]);
38
+ var name = _a.name, Component = _a.Component, id = _a.id, disabled = _a.disabled, validate = _a.validate, normalize = _a.normalize, rest = __rest(_a, ["name", "Component", "id", "disabled", "validate", "normalize"]);
38
39
  var _b = (0, useStandardField_1.default)({
39
40
  name: String(name),
40
41
  id: id,
41
- normalize: normalize,
42
- validate: validate,
43
42
  disabled: disabled,
43
+ validate: validate,
44
+ normalize: normalize,
44
45
  }), input = _b[0], meta = _b[1];
46
+ var isRequired = (rest === null || rest === void 0 ? void 0 : rest.required) !== undefined
47
+ ? rest.required
48
+ : validate === validators_1.required ||
49
+ (Array.isArray(validate) && validate.includes(validators_1.required));
45
50
  // a bit of a hack so JSX is happy with us
46
51
  var Wrapped = Component;
47
- return ((0, jsx_runtime_1.jsx)(FieldNameContext_1.FieldNameContext.Provider, __assign({ value: input.name }, { children: (0, jsx_runtime_1.jsx)(Wrapped, __assign({}, rest, { ref: ref, id: input.id, input: input, meta: meta, disabled: disabled })) })));
52
+ return ((0, jsx_runtime_1.jsx)(FieldNameContext_1.FieldNameContext.Provider, __assign({ value: input.name }, { children: (0, jsx_runtime_1.jsx)(Wrapped, __assign({}, rest, { ref: ref, id: input.id, input: input, meta: meta, required: isRequired, disabled: disabled })) })));
48
53
  }
49
54
  // hack to get forwarded refs to work
50
55
  var FieldWithRef = react_1.default.forwardRef(Field);
@@ -1,2 +1,3 @@
1
1
  /// <reference types="react" />
2
+ /** Hidden `<div/>` that acts as an anchor to scroll to when a form error occurs. */
2
3
  export default function FieldErrorScrollTarget(): JSX.Element | null;
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  var jsx_runtime_1 = require("react/jsx-runtime");
4
4
  var react_1 = require("react");
5
5
  var FieldNameContext_1 = require("./FieldNameContext");
6
+ /** Hidden `<div/>` that acts as an anchor to scroll to when a form error occurs. */
6
7
  function FieldErrorScrollTarget() {
7
8
  var name = (0, react_1.useContext)(FieldNameContext_1.FieldNameContext);
8
9
  if (!name) {
@@ -2,8 +2,12 @@ import { ElementType } from 'react';
2
2
  import { RenderComponent, RenderComponentProps } from './Field';
3
3
  import { InjectedFieldProps } from './InjectedFieldProps';
4
4
  export declare type StandAloneInputProps<TValue, TRenderComponent extends ElementType> = {
5
+ /** Component to render inside of the field. */
5
6
  Component: RenderComponent<TValue, TRenderComponent>;
7
+ /** Value of the field. */
6
8
  value: TValue;
9
+ /** Function to change the value of the field. */
7
10
  onChange: (arg: TValue) => void;
8
11
  } & Omit<RenderComponentProps<TValue, TRenderComponent>, keyof InjectedFieldProps<TValue> | 'value' | 'onChange' | 'normalize' | 'validate'>;
12
+ /** The stand alone version of `<Field/>`. Can use a type of input component outside of a `<Form/>`. */
9
13
  export default function StandAloneInput<TValue, TComponent extends ElementType>(props: StandAloneInputProps<TValue, TComponent>): JSX.Element;
@@ -48,6 +48,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
48
48
  var jsx_runtime_1 = require("react/jsx-runtime");
49
49
  var react_1 = require("react");
50
50
  var uuid = __importStar(require("uuid"));
51
+ /** The stand alone version of `<Field/>`. Can use a type of input component outside of a `<Form/>`. */
51
52
  function StandAloneInput(props) {
52
53
  var Component = props.Component, value = props.value, onChange = props.onChange, disabled = props.disabled, rest = __rest(props, ["Component", "value", "onChange", "disabled"]);
53
54
  var handleChange = function (arg) {
@@ -3,12 +3,18 @@ import { CustomFieldMetaProps } from './CustomFieldMetaProps';
3
3
  import { NormalizationFunction } from '../Normalization/NormalizationFunction';
4
4
  import { ValidationFunction } from '../Validation/ValidationFunction';
5
5
  export interface useStandardFieldProps<TValue> {
6
+ /** Id of the field. */
6
7
  id?: string;
8
+ /** Name of the field. */
7
9
  name: string;
10
+ /** Whether the field should be disabled. */
8
11
  disabled?: boolean;
12
+ /** Function to validate the field. */
9
13
  validate?: ValidationFunction<TValue> | ValidationFunction<TValue>[];
14
+ /** Function to modify the field value without making the form dirty. (e.g. phone number) */
10
15
  normalize?: NormalizationFunction<TValue>;
11
16
  }
17
+ /** Provides a consistent way to deal with all form fields (non array). */
12
18
  export default function useStandardField<TValue>({ id: providedId, name: providedName, disabled, validate, normalize, }: useStandardFieldProps<TValue>): [
13
19
  CustomFieldInputProps<TValue>,
14
20
  CustomFieldMetaProps<TValue>
@@ -15,7 +15,7 @@ var react_1 = require("react");
15
15
  var formik_1 = require("formik");
16
16
  var FieldNameContext_1 = require("./FieldNameContext");
17
17
  var ServerErrorContext_1 = require("../Form/ServerErrorContext");
18
- // provides a consistent way to deal with all form fields (non array)
18
+ /** Provides a consistent way to deal with all form fields (non array). */
19
19
  function useStandardField(_a) {
20
20
  var providedId = _a.id, providedName = _a.name, disabled = _a.disabled, validate = _a.validate, normalize = _a.normalize;
21
21
  // because the formik errors are evaluated all at the same time we need to keep server errors separate
@@ -39,20 +39,19 @@ function useStandardField(_a) {
39
39
  disabled: disabled,
40
40
  validate: callAllValidators,
41
41
  }), formikInput = _c[0], formikMeta = _c[1];
42
- var _d = (0, formik_1.useFormikContext)(), setFieldValue = _d.setFieldValue, isSubmitting = _d.isSubmitting;
42
+ var _d = (0, formik_1.useFormikContext)(), setFieldTouched = _d.setFieldTouched, setFieldValue = _d.setFieldValue, isSubmitting = _d.isSubmitting;
43
43
  var touched = formikMeta.touched !== false && formikMeta.touched !== undefined;
44
44
  (0, react_1.useEffect)(function () {
45
45
  if (!touched && isSubmitting) {
46
46
  // because we do not always register all fields up front.
47
47
  // e.g. formik expects even a 'create' form to have all fields given, at least, blank values
48
- // that seems to be how it touches on submit:
49
- // see: https://codesandbox.io/s/formik-example-4n7n8 vs https://codesandbox.io/s/formik-example-kttk5
50
- // note in particular the change in line 24
51
- // thus, we manually touch all fields here by calling onBlur
52
- // there is a "setFieldTouched" from useFormikContext but it doesn't appear to work on field arrays
53
- handleBlur();
48
+ // It looks like this was going to be a thing: https://github.com/jaredpalmer/formik/issues/691
49
+ // Formik appears to not have an active maintainer: https://github.com/jaredpalmer/formik/discussions/3526
50
+ // We previously had a different fix in place using handleBlur, but it was causing an infinite update cycle.
51
+ // This was noted as existing, but there was a note about it not working for FieldArray (this does appear to work in my testing with FieldArray)
52
+ setFieldTouched(name);
54
53
  }
55
- });
54
+ }, [isSubmitting, name, setFieldTouched, touched]);
56
55
  // these are the props we expect consumers of this hook to pass directly to the input (or other control)
57
56
  var resultInput = {
58
57
  name: formikInput.name,
@@ -1,15 +1,24 @@
1
1
  import { ElementType } from 'react';
2
2
  import { FieldProps } from '../Field/Field';
3
3
  import { ValidationFunction } from '../Validation/ValidationFunction';
4
- export declare type FieldArrayProps<TForm extends object, TProp extends keyof TForm> = TForm[TProp] extends Array<any> | undefined ? {
4
+ export declare type FieldArrayProps<TForm extends object, TProp extends keyof TForm> = TForm[TProp] extends Array<any> | undefined | null ? {
5
+ /** Name of the field, used on submission. If using codegen this must be the provided dto. */
5
6
  name: TProp;
7
+ /** Label of the field. */
6
8
  label?: string;
9
+ /** Whether the field should be disabled. */
7
10
  disabled?: boolean;
11
+ /** Function to validate the value. */
8
12
  validate?: ValidationFunction<TForm[TProp]> | ValidationFunction<TForm[TProp]>[];
9
13
  children: (formBuilder: ArrayFormBuilderProp<TForm[TProp]>) => JSX.Element;
10
14
  } : never;
11
- export declare type ArrayFormBuilderProp<TValue extends Array<any> | undefined> = TValue extends Array<infer TForm> | undefined ? TForm extends object ? {
15
+ export declare type ArrayFormBuilderProp<TValue extends Array<any> | undefined | null> = TValue extends Array<infer TForm> | undefined | null ? TForm extends object ? {
12
16
  Field: <TProp extends keyof TForm, TRenderComponent extends ElementType>(props: FieldProps<TForm, TProp, TRenderComponent>) => JSX.Element;
13
17
  FieldArray: <TProp extends keyof TForm>(props: FieldArrayProps<TForm, TProp>) => JSX.Element;
14
18
  } : never : never;
19
+ /**
20
+ * An array of fields that allows the user to add multiple instances of the same field.
21
+ *
22
+ * Includes "Add Item" and "Remove Item" buttons to allow the user to speicify the number of fields.
23
+ */
15
24
  export default function FieldArray<TForm extends object, TProp extends keyof TForm>({ name, label, validate, disabled, children, ...rest }: FieldArrayProps<TForm, TProp>): JSX.Element;
@@ -40,14 +40,19 @@ var Field_1 = __importDefault(require("../Field/Field"));
40
40
  var FieldNameContext_1 = require("../Field/FieldNameContext");
41
41
  var useStandardField_1 = __importDefault(require("../Field/useStandardField"));
42
42
  var FormDefaults_1 = require("../FormDefaults");
43
+ /**
44
+ * An array of fields that allows the user to add multiple instances of the same field.
45
+ *
46
+ * Includes "Add Item" and "Remove Item" buttons to allow the user to speicify the number of fields.
47
+ */
43
48
  function FieldArray(_a) {
44
49
  var _b;
45
50
  var name = _a.name, label = _a.label, validate = _a.validate, disabled = _a.disabled, children = _a.children, rest = __rest(_a, ["name", "label", "validate", "disabled", "children"]);
46
- var _c = (0, useStandardField_1.default)({
51
+ var input = (0, useStandardField_1.default)({
47
52
  name: String(name),
48
53
  validate: validate,
49
54
  disabled: disabled,
50
- }), input = _c[0], meta = _c[1];
55
+ })[0];
51
56
  var values = !input.value
52
57
  ? []
53
58
  : Array.isArray(input.value)
@@ -1,8 +1,10 @@
1
1
  import React from 'react';
2
2
  import { InjectedFieldProps } from '../Field/InjectedFieldProps';
3
3
  import { GroupProps } from '../Group';
4
- export interface FileGroupProps extends InjectedFieldProps<any | undefined>, Omit<GroupProps, keyof InjectedFieldProps<any> | 'children'>, Omit<React.HTMLProps<HTMLInputElement>, keyof InjectedFieldProps<any> | 'children' | 'className' | 'label'> {
4
+ export interface FileGroupProps extends InjectedFieldProps<any | undefined | null>, Omit<GroupProps, keyof InjectedFieldProps<any> | 'children'>, Omit<React.HTMLProps<HTMLInputElement>, keyof InjectedFieldProps<any> | 'children' | 'className' | 'label'> {
5
+ /** Allow multiple files to be uploaded. */
5
6
  multiple?: boolean | undefined;
6
7
  }
8
+ /** File upload input group. */
7
9
  declare const FileGroupWithRef: React.ComponentType<FileGroupProps>;
8
10
  export default FileGroupWithRef;