@o3r/forms 12.3.0-prerelease.45 → 12.3.0-prerelease.47

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 (2) hide show
  1. package/README.md +14 -78
  2. package/package.json +4 -4
package/README.md CHANGED
@@ -12,7 +12,20 @@ This package is an [Otter Framework Module](https://github.com/AmadeusITGroup/ot
12
12
  [![Stable Version](https://img.shields.io/npm/v/@o3r/forms?style=for-the-badge)](https://www.npmjs.com/package/@o3r/forms)
13
13
  [![Bundle Size](https://img.shields.io/bundlephobia/min/@o3r/forms?color=green&style=for-the-badge)](https://www.npmjs.com/package/@o3r/forms)
14
14
 
15
- This module provides utilities to enhance Angular form (asynchronous decorator, additional validator, error store...).
15
+ One of the approaches for writing forms that Angular provides is called [model-driven or reactive forms](https://angular.io/guide/reactive-forms),
16
+ which _"provide a model-driven approach to handling form inputs whose values change over time"_. This type of form is applicable in many use cases,
17
+ but there are a couple of exceptions where additional utilities may be useful.
18
+
19
+ These use cases include:
20
+ * A container/presenter structure for components
21
+ * Handling form submission at page level
22
+ * Displaying the error message outside the form
23
+
24
+ To handle these, this module provides utilities to enhance the build of Angular reactive forms, including:
25
+ * An asynchronous decorator (`@AsyncInput`) to ensure subscriptions are handled if the references of the input observables change.
26
+ * Basic and custom validators to validate user input for accuracy and completeness.
27
+ * A dedicated NgRX store for form errors to have the possibility of displaying error messages outside the form component.
28
+ * Helper functions to handle the interactions with the forms.
16
29
 
17
30
  ## How to install
18
31
 
@@ -23,83 +36,6 @@ ng add @o3r/forms
23
36
  > [!WARNING]
24
37
  > This module requires [@o3r/core](https://www.npmjs.com/package/@o3r/core) to be installed.
25
38
 
26
- ## Container/presenter and form creation
27
-
28
- A Container/presenter architecture was put in place to ensure best reusability/sharing
29
-
30
- ### Where the form object creation should be done?
31
-
32
- * **form created in presenter** - it's the presenter that decides how the data is displayed
33
- * **container** only values and errors are propagated from the presenter
34
- * **container** can set the default value
35
-
36
- ### How the container and presenter will communicate in forms context
37
-
38
- * **presenter** implements [ControlValueAccessor](https://angular.io/api/forms/ControlValueAccessor) and [Validator](https://angular.io/api/forms/Validator) (or [AsyncValidator](https://angular.io/api/forms/AsyncValidator)) interfaces
39
- * **propagate** the value, the form status and the errors
40
- * **container** applies [FormControlDirective](https://angular.io/api/forms/FormControlDirective) on the presenter html tag
41
- * **container** sets the default value using **formControl** directive
42
- * **listen** to the value and status changes using the same directive
43
-
44
- See [FORM_STRUCTURE](https://github.com/AmadeusITGroup/otter/tree/main/docs/forms/FORM_STRUCTURE.md)
45
-
46
- ## You want to include form validation and display the errors
47
-
48
- * interfaces for the error messages provided in **@o3r/forms**
49
-
50
- ### Display inline errors
51
-
52
- * the error messages returned by validators are used in the inline error display
53
- * **simple/basic/primitive** validators - set as a configuration of the **presenter**
54
- * localization of the associated error messages from the presenter
55
- * the error object associated is computed here and has to be compliant with the store object model
56
- * _getFlatControlErrors_ function is available in **@o3r/forms** to help with the creation of the associated error object
57
- * **custom** validators created at container level
58
- * localization of the associated error messages from the container
59
- * custom validators are passed as an input to the presenter
60
- * the error returned by the validator has to be compliant with the form error store model
61
-
62
- ### Display errors on a messages panel
63
-
64
- * a dedicated _FormErrorStore_ is available on **@o3r/forms**
65
- * allows the display of errors anywhere on the page
66
- * the error object model contains the translation key and params
67
- See [FORM_VALIDATION](https://github.com/AmadeusITGroup/otter/tree/main/docs/forms/FORM_VALIDATION.md) and [FORM_ERRORS](https://github.com/AmadeusITGroup/otter/tree/main/docs/forms/FORM_ERRORS.md)
68
-
69
- ## Form submit
70
-
71
- ### You want to submit the form
72
-
73
- * The submit is triggered by the submit button **in the presenter** and an event is emitted
74
- * **container** captures the event and executes the submit form logic
75
-
76
- ### What happens when you have multiple forms and you want to submit?
77
-
78
- The answer is that we should avoid as much as possible having multiple form tags in the same page as it adds a lot of complexity. We should try to have only one _form_ tag that encapsulates everything and one submit action.
79
-
80
- If multiple forms are really needed, then we found the following solution:
81
-
82
- * the submit button is hidden on the presenters
83
- * the **submit** is **triggered from the page**
84
- * an **observable** to trigger the submit is passed as **input** to the containers;
85
- * _AsyncInput_ decorator is provided in **@o3r/forms** to be applied on the observable input to ensure performance
86
- * the submit form logic is executed on the containers
87
- * containers emit events when the submit is done
88
- * the page (parent) captures the events and continues its logic
89
-
90
- This can be applied also, with only one form on the page, when you don't want a submit button in the presenter.
91
-
92
- ### What happens when the submit is triggered by the page with pristine forms
93
-
94
- At the first display of the form, the inline errors (if the form is invalid) are not displayed because the form element is **not touched** and **dirty**
95
- In case you want to show the inline errors after the submit, you have to:
96
-
97
- * register a function in the container to _mark touched and dirty_ the form
98
- * pass the function via an _@Output_ from the presenter and call it before executing the submit logic
99
- * use _markAllControlsDirtyAndTouched_ helper is available in **@o3r/forms** to mark interactions on given form
100
-
101
- See [FORM_SUBMIT&INTERCOMMUNICATION](https://github.com/AmadeusITGroup/otter/tree/main/docs/forms/FORM_SUBMIT_AND_INTERCOMMUNICATION.md)
102
-
103
39
  ## Details
104
40
 
105
41
  Find more information in the [documentation](https://github.com/AmadeusITGroup/otter/tree/main/docs/forms).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@o3r/forms",
3
- "version": "12.3.0-prerelease.45",
3
+ "version": "12.3.0-prerelease.47",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -11,15 +11,15 @@
11
11
  "otter-module"
12
12
  ],
13
13
  "peerDependencies": {
14
- "@ama-sdk/core": "^12.3.0-prerelease.45",
14
+ "@ama-sdk/core": "^12.3.0-prerelease.47",
15
15
  "@angular-devkit/schematics": "^19.0.0",
16
16
  "@angular/common": "^19.0.0",
17
17
  "@angular/core": "^19.0.0",
18
18
  "@angular/forms": "^19.0.0",
19
19
  "@ngrx/entity": "^19.0.0",
20
20
  "@ngrx/store": "^19.0.0",
21
- "@o3r/core": "^12.3.0-prerelease.45",
22
- "@o3r/schematics": "^12.3.0-prerelease.45",
21
+ "@o3r/core": "^12.3.0-prerelease.47",
22
+ "@o3r/schematics": "^12.3.0-prerelease.47",
23
23
  "@schematics/angular": "^19.0.0",
24
24
  "rxjs": "^7.8.1",
25
25
  "ts-node": "~10.9.2"