remix-validated-form 4.1.9 → 4.2.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.
@@ -1,9 +1,9 @@
1
1
  $ npm run build:browser && npm run build:main
2
2
 
3
- > remix-validated-form@4.1.8 build:browser
3
+ > remix-validated-form@4.1.9 build:browser
4
4
  > tsc --module ESNext --outDir ./browser
5
5
 
6
6
 
7
- > remix-validated-form@4.1.8 build:main
7
+ > remix-validated-form@4.1.9 build:main
8
8
  > tsc --module CommonJS --outDir ./build
9
9
 
package/README.md CHANGED
@@ -71,9 +71,7 @@ export const MyInput = ({ name, label }: MyInputProps) => {
71
71
  <div>
72
72
  <label htmlFor={name}>{label}</label>
73
73
  <input {...getInputProps({ id: name })} />
74
- {error && (
75
- <span className="my-error-class">{error}</span>
76
- )}
74
+ {error && <span className="my-error-class">{error}</span>}
77
75
  </div>
78
76
  );
79
77
  };
@@ -92,14 +90,17 @@ export const MySubmitButton = () => {
92
90
  const disabled = isSubmitting || !isValid;
93
91
 
94
92
  return (
95
- <button type="submit" disabled={disabled} className={disabled ? "disabled-btn" : "btn"}>
93
+ <button
94
+ type="submit"
95
+ disabled={disabled}
96
+ className={disabled ? "disabled-btn" : "btn"}
97
+ >
96
98
  {isSubmitting ? "Submitting..." : "Submit"}
97
99
  </button>
98
100
  );
99
101
  };
100
102
  ```
101
103
 
102
-
103
104
  ## Use the form!
104
105
 
105
106
  Now that we have our components, making a form is easy!
@@ -258,5 +259,6 @@ Problem: how do we trigger a toast message on success if the action redirects aw
258
259
  See the [Remix](https://remix.run/docs/en/v1/api/remix#sessionflashkey-value) documentation for more information.
259
260
 
260
261
  ## Why is my cancel button triggering form submission?
262
+
261
263
  Problem: the cancel button has an onClick handler to navigate away from the form route but instead it is submitting the form.
262
264
  A button defaults to `type="submit"` in a form which will submit the form by default. If you want to prevent this you can add `type="reset"` or `type="button"` to the cancel button.
@@ -14,7 +14,7 @@ import { ValidatorError } from "./validation/types";
14
14
  * if (result.error) return validationError(result.error, result.submittedData);
15
15
  * ```
16
16
  */
17
- export declare function validationError(error: ValidatorError, repopulateFields?: unknown): Response;
17
+ export declare function validationError(error: ValidatorError, repopulateFields?: unknown, init?: ResponseInit): Response;
18
18
  export declare type FormDefaults = {
19
19
  [formDefaultsKey: `${typeof FORM_DEFAULTS_FIELD}_${string}`]: any;
20
20
  };
package/browser/server.js CHANGED
@@ -14,13 +14,13 @@ import { formDefaultValuesKey, } from "./internal/constants";
14
14
  * if (result.error) return validationError(result.error, result.submittedData);
15
15
  * ```
16
16
  */
17
- export function validationError(error, repopulateFields) {
17
+ export function validationError(error, repopulateFields, init) {
18
18
  return json({
19
19
  fieldErrors: error.fieldErrors,
20
20
  subaction: error.subaction,
21
21
  repopulateFields,
22
22
  formId: error.formId,
23
- }, { status: 422 });
23
+ }, { status: 422, ...init });
24
24
  }
25
25
  export const setFormDefaults = (formId, defaultValues) => ({
26
26
  [formDefaultValuesKey(formId)]: defaultValues,
package/build/server.d.ts CHANGED
@@ -14,7 +14,7 @@ import { ValidatorError } from "./validation/types";
14
14
  * if (result.error) return validationError(result.error, result.submittedData);
15
15
  * ```
16
16
  */
17
- export declare function validationError(error: ValidatorError, repopulateFields?: unknown): Response;
17
+ export declare function validationError(error: ValidatorError, repopulateFields?: unknown, init?: ResponseInit): Response;
18
18
  export declare type FormDefaults = {
19
19
  [formDefaultsKey: `${typeof FORM_DEFAULTS_FIELD}_${string}`]: any;
20
20
  };
package/build/server.js CHANGED
@@ -17,13 +17,13 @@ const constants_1 = require("./internal/constants");
17
17
  * if (result.error) return validationError(result.error, result.submittedData);
18
18
  * ```
19
19
  */
20
- function validationError(error, repopulateFields) {
20
+ function validationError(error, repopulateFields, init) {
21
21
  return (0, server_runtime_1.json)({
22
22
  fieldErrors: error.fieldErrors,
23
23
  subaction: error.subaction,
24
24
  repopulateFields,
25
25
  formId: error.formId,
26
- }, { status: 422 });
26
+ }, { status: 422, ...init });
27
27
  }
28
28
  exports.validationError = validationError;
29
29
  const setFormDefaults = (formId, defaultValues) => ({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "remix-validated-form",
3
- "version": "4.1.9",
3
+ "version": "4.2.0",
4
4
  "description": "Form component and utils for easy form validation in remix",
5
5
  "browser": "./browser/index.js",
6
6
  "main": "./build/index.js",
package/src/server.ts CHANGED
@@ -24,7 +24,8 @@ import {
24
24
  */
25
25
  export function validationError(
26
26
  error: ValidatorError,
27
- repopulateFields?: unknown
27
+ repopulateFields?: unknown,
28
+ init?: ResponseInit
28
29
  ): Response {
29
30
  return json<ValidationErrorResponseData>(
30
31
  {
@@ -33,7 +34,7 @@ export function validationError(
33
34
  repopulateFields,
34
35
  formId: error.formId,
35
36
  },
36
- { status: 422 }
37
+ { status: 422, ...init }
37
38
  );
38
39
  }
39
40