@opentf/afw-form 1.29.0 → 1.31.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 (3) hide show
  1. package/README.md +1 -0
  2. package/index.js +10 -1
  3. package/package.json +5 -5
package/README.md CHANGED
@@ -139,6 +139,7 @@ order in the component body. Several forms in one component stay independent.
139
139
  | `register(path)` | Props to spread onto an input |
140
140
  | `handleSubmit(fn)` | Submit handler: validates, then calls `fn(values)` when valid |
141
141
  | `reset(values?)` | Restore `initialValues`, or reset to new baseline values |
142
+ | `setError(path, message)` | Set a field's error from outside the validator (a server refusing the submit); an empty message clears it |
142
143
  | `values`, `errors`, `touched`, `changed` | Reactive stores, read by path |
143
144
  | `isValid`, `isChanged`, `isTouched` | Form-wide status |
144
145
  | `isSubmitting`, `isValidating`, `isSubmitted`, `submitCount` | Submission status |
package/index.js CHANGED
@@ -12,7 +12,7 @@ import {
12
12
 
13
13
  export { signal, computed, batch, effect, untracked, reactive, getCurrentInstance };
14
14
 
15
- import { clone, isEql } from "@opentf/std";
15
+ import { clone, isEqual as isEql } from "@opentf/std";
16
16
 
17
17
  /**
18
18
  * Path-based reactive forms engine for AFW.
@@ -259,6 +259,14 @@ function _createForm(options = {}) {
259
259
  });
260
260
  };
261
261
 
262
+ // An error from outside the validator — typically the server refusing a submit.
263
+ // An empty message clears it; the next validation of the field, or reset(),
264
+ // replaces it like any other error.
265
+ const setError = (path, message) => {
266
+ if (message) writePath(errorsStore, path, message);
267
+ else deletePath(errorsStore, path);
268
+ };
269
+
262
270
  // --- derived flags
263
271
  const isValidSig = computed(() => !hasTruthy(errorsStore));
264
272
  const isTouchedSig = computed(() => hasTruthy(touchedStore));
@@ -268,6 +276,7 @@ function _createForm(options = {}) {
268
276
  register,
269
277
  handleSubmit,
270
278
  reset,
279
+ setError,
271
280
  _updateConfig(newMode, newReValidateMode) {
272
281
  batch(() => {
273
282
  modeSig.value = newMode;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opentf/afw-form",
3
- "version": "1.29.0",
3
+ "version": "1.31.0",
4
4
  "description": "Path-based reactive forms for AFW.",
5
5
  "main": "index.js",
6
6
  "module": "index.js",
@@ -31,16 +31,16 @@
31
31
  "bugs": "https://github.com/Open-Tech-Foundation/afw/issues",
32
32
  "license": "MIT",
33
33
  "dependencies": {
34
- "@opentf/std": "^0.19.0"
34
+ "@opentf/std": "^0.20.0"
35
35
  },
36
36
  "peerDependencies": {
37
- "@opentf/afw": "0.34.0"
37
+ "@opentf/afw": "0.36.0"
38
38
  },
39
39
  "publishConfig": {
40
40
  "access": "public"
41
41
  },
42
42
  "devDependencies": {
43
- "@opentf/afw": "0.34.0",
44
- "@opentf/afw-test": "1.29.0"
43
+ "@opentf/afw": "0.36.0",
44
+ "@opentf/afw-test": "1.31.0"
45
45
  }
46
46
  }