ngx-form-draft 2.2.11 → 2.2.12

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/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 Neokyuubi
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Neokyuubi
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,206 +1,206 @@
1
- # ngx-form-draft
2
-
3
- Zero-dependency Angular form draft auto-save and restore. Works with Angular 14-20.
4
-
5
- ## Features
6
-
7
- - Auto-saves form values to localStorage
8
- - Restores drafts on page reload
9
- - Works with Reactive and Template-driven forms
10
- - Handles nested FormGroups and FormArrays
11
- - Visual banner with discard option
12
- - 7-day draft expiration
13
- - Zero external dependencies
14
- - No Angular animations required (pure CSS)
15
-
16
- ## Requirements
17
-
18
- - Angular 14-20
19
- - TypeScript 4.7+
20
-
21
- > **Note:** Angular 21+ support is not yet tested. The package uses stable Angular APIs that should work, but may require updates for newer versions. Please report any issues.
22
-
23
- ## Installation
24
-
25
- ```bash
26
- npm install ngx-form-draft
27
- ```
28
-
29
- ## Demo
30
-
31
- **Live demo:** https://neokyuubi.github.io/ngx-form-draft/
32
-
33
- ## Setup
34
-
35
- ### 1. Import the module
36
-
37
- ```typescript
38
- import { NgxFormDraftModule } from 'ngx-form-draft';
39
-
40
- @NgModule({
41
- imports: [NgxFormDraftModule]
42
- })
43
- export class AppModule {}
44
- ```
45
-
46
- ## Usage
47
-
48
- ### Reactive Forms
49
-
50
- ```html
51
- <form [formGroup]="myForm" ngxFormDraft="uniqueFormId">
52
- <input formControlName="name">
53
- <input formControlName="email">
54
- </form>
55
- ```
56
-
57
- ### Template-driven Forms
58
-
59
- ```html
60
- <form #myForm="ngForm" ngxFormDraft="uniqueFormId">
61
- <input name="name" [(ngModel)]="model.name">
62
- <input name="email" [(ngModel)]="model.email">
63
- </form>
64
- ```
65
-
66
- ### Scoped drafts (per entity)
67
-
68
- ```html
69
- <!-- Reactive -->
70
- <form [formGroup]="editForm" [ngxFormDraft]="'edit_' + userId">
71
-
72
- <!-- Template-driven -->
73
- <form #editForm="ngForm" [ngxFormDraft]="'edit_' + userId">
74
- ```
75
-
76
- ## Options
77
-
78
- ### Reactive Forms
79
- ```html
80
- <form
81
- [formGroup]="myForm"
82
- [ngxFormDraft]="'myForm_' + entityId"
83
- [draftDebounce]="1000"
84
- [draftExcludeFields]="['password', 'confirmPassword']"
85
- [draftShowOnChange]="true"
86
- [draftRestoredText]="'Draft restored'"
87
- [draftSavedText]="'Draft saved'"
88
- [draftSavedLabel]="'saved'"
89
- [draftDiscardText]="'Discard'">
90
- </form>
91
- ```
92
-
93
- ### Template-driven Forms
94
- ```html
95
- <form
96
- #myForm="ngForm"
97
- [ngxFormDraft]="'myForm_' + entityId"
98
- [draftDebounce]="1000"
99
- [draftExcludeFields]="['password', 'confirmPassword']"
100
- [draftShowOnChange]="true"
101
- [draftRestoredText]="'Draft restored'"
102
- [draftSavedText]="'Draft saved'"
103
- [draftSavedLabel]="'saved'"
104
- [draftDiscardText]="'Discard'">
105
- </form>
106
- ```
107
-
108
- ### Input Properties
109
-
110
- - `ngxFormDraft` (string): Unique form identifier
111
- - `draftDebounce` (number): Debounce time in ms (default: 800)
112
- - `draftExcludeFields` (string[]): Fields to exclude from draft
113
- - `draftShowOnChange` (boolean): Show banner immediately on change (default: false)
114
- - `draftRestoredText` (string): Banner text for restored draft
115
- - `draftSavedText` (string): Banner text for saved draft
116
- - `draftSavedLabel` (string): Label before timestamp
117
- - `draftDiscardText` (string): Discard button text
118
-
119
- ## Clearing the draft
120
-
121
- The draft is not cleared automatically on form submit. To clear it (e.g. after a successful submit), use **FormDraftService** — the same for both reactive and template-driven forms.
122
-
123
- Inject the service and call `clear(formId)` with the same `formId` you use on the form:
124
-
125
- ```typescript
126
- import { FormDraftService } from 'ngx-form-draft';
127
-
128
- export class MyComponent {
129
- constructor(private draftService: FormDraftService) {}
130
-
131
- onSubmit() {
132
- this.myForm.markAllAsTouched();
133
- if (this.myForm.invalid) return;
134
- // ... submit to API ...
135
- this.draftService.clear('uniqueFormId'); // same id as ngxFormDraft
136
- }
137
- }
138
- ```
139
-
140
- Users can also clear the draft at any time via the banner’s **Discard** button.
141
-
142
- ## Internationalization (i18n)
143
-
144
- The package has **zero dependencies** and supports any i18n solution. Just pass translated strings via inputs:
145
-
146
- ### With ngx-translate:
147
- ```html
148
- <form
149
- [formGroup]="myForm"
150
- ngxFormDraft="myForm"
151
- [draftRestoredText]="'form_draft.restored' | translate"
152
- [draftSavedText]="'form_draft.saved' | translate"
153
- [draftSavedLabel]="'form_draft.saved_label' | translate"
154
- [draftDiscardText]="'form_draft.discard' | translate">
155
- </form>
156
- ```
157
-
158
- ### With Angular i18n:
159
- ```html
160
- <form
161
- [formGroup]="myForm"
162
- ngxFormDraft="myForm"
163
- [draftRestoredText]="restoredText"
164
- [draftSavedText]="savedText"
165
- [draftDiscardText]="discardText"
166
- i18n-draftRestoredText="@@formDraftRestored"
167
- i18n-draftSavedText="@@formDraftSaved"
168
- i18n-draftDiscardText="@@formDraftDiscard">
169
- </form>
170
- ```
171
-
172
- ### With component properties:
173
- ```typescript
174
- // component.ts
175
- export class MyComponent {
176
- draftTexts = {
177
- restored: 'Brouillon restauré',
178
- saved: 'Brouillon sauvegardé',
179
- savedLabel: 'sauvegardé',
180
- discard: 'Supprimer'
181
- };
182
- }
183
- ```
184
-
185
- ```html
186
- <!-- template.html -->
187
- <form
188
- [formGroup]="myForm"
189
- ngxFormDraft="myForm"
190
- [draftRestoredText]="draftTexts.restored"
191
- [draftSavedText]="draftTexts.saved"
192
- [draftSavedLabel]="draftTexts.savedLabel"
193
- [draftDiscardText]="draftTexts.discard">
194
- </form>
195
- ```
196
-
197
- ### Default English text:
198
- If you don't provide any text inputs, defaults are:
199
- - `draftRestoredText`: "Draft restored"
200
- - `draftSavedText`: "Draft saved"
201
- - `draftSavedLabel`: "saved"
202
- - `draftDiscardText`: "Discard"
203
-
204
- ## License
205
-
206
- MIT
1
+ # ngx-form-draft
2
+
3
+ Zero-dependency Angular form draft auto-save and restore. Works with Angular 14-20.
4
+
5
+ ## Features
6
+
7
+ - Auto-saves form values to localStorage
8
+ - Restores drafts on page reload
9
+ - Works with Reactive and Template-driven forms
10
+ - Handles nested FormGroups and FormArrays
11
+ - Visual banner with discard option
12
+ - 7-day draft expiration
13
+ - Zero external dependencies
14
+ - No Angular animations required (pure CSS)
15
+
16
+ ## Requirements
17
+
18
+ - Angular 14-20
19
+ - TypeScript 4.7+
20
+
21
+ > **Note:** Angular 21+ support is not yet tested. The package uses stable Angular APIs that should work, but may require updates for newer versions. Please report any issues.
22
+
23
+ ## Installation
24
+
25
+ ```bash
26
+ npm install ngx-form-draft
27
+ ```
28
+
29
+ ## Demo
30
+
31
+ **Live demo:** https://neokyuubi.github.io/ngx-form-draft/
32
+
33
+ ## Setup
34
+
35
+ ### 1. Import the module
36
+
37
+ ```typescript
38
+ import { NgxFormDraftModule } from 'ngx-form-draft';
39
+
40
+ @NgModule({
41
+ imports: [NgxFormDraftModule]
42
+ })
43
+ export class AppModule {}
44
+ ```
45
+
46
+ ## Usage
47
+
48
+ ### Reactive Forms
49
+
50
+ ```html
51
+ <form [formGroup]="myForm" ngxFormDraft="uniqueFormId">
52
+ <input formControlName="name">
53
+ <input formControlName="email">
54
+ </form>
55
+ ```
56
+
57
+ ### Template-driven Forms
58
+
59
+ ```html
60
+ <form #myForm="ngForm" ngxFormDraft="uniqueFormId">
61
+ <input name="name" [(ngModel)]="model.name">
62
+ <input name="email" [(ngModel)]="model.email">
63
+ </form>
64
+ ```
65
+
66
+ ### Scoped drafts (per entity)
67
+
68
+ ```html
69
+ <!-- Reactive -->
70
+ <form [formGroup]="editForm" [ngxFormDraft]="'edit_' + userId">
71
+
72
+ <!-- Template-driven -->
73
+ <form #editForm="ngForm" [ngxFormDraft]="'edit_' + userId">
74
+ ```
75
+
76
+ ## Options
77
+
78
+ ### Reactive Forms
79
+ ```html
80
+ <form
81
+ [formGroup]="myForm"
82
+ [ngxFormDraft]="'myForm_' + entityId"
83
+ [draftDebounce]="1000"
84
+ [draftExcludeFields]="['password', 'confirmPassword']"
85
+ [draftShowOnChange]="true"
86
+ [draftRestoredText]="'Draft restored'"
87
+ [draftSavedText]="'Draft saved'"
88
+ [draftSavedLabel]="'saved'"
89
+ [draftDiscardText]="'Discard'">
90
+ </form>
91
+ ```
92
+
93
+ ### Template-driven Forms
94
+ ```html
95
+ <form
96
+ #myForm="ngForm"
97
+ [ngxFormDraft]="'myForm_' + entityId"
98
+ [draftDebounce]="1000"
99
+ [draftExcludeFields]="['password', 'confirmPassword']"
100
+ [draftShowOnChange]="true"
101
+ [draftRestoredText]="'Draft restored'"
102
+ [draftSavedText]="'Draft saved'"
103
+ [draftSavedLabel]="'saved'"
104
+ [draftDiscardText]="'Discard'">
105
+ </form>
106
+ ```
107
+
108
+ ### Input Properties
109
+
110
+ - `ngxFormDraft` (string): Unique form identifier
111
+ - `draftDebounce` (number): Debounce time in ms (default: 800)
112
+ - `draftExcludeFields` (string[]): Fields to exclude from draft
113
+ - `draftShowOnChange` (boolean): Show banner immediately on change (default: false)
114
+ - `draftRestoredText` (string): Banner text for restored draft
115
+ - `draftSavedText` (string): Banner text for saved draft
116
+ - `draftSavedLabel` (string): Label before timestamp
117
+ - `draftDiscardText` (string): Discard button text
118
+
119
+ ## Clearing the draft
120
+
121
+ The draft is not cleared automatically on form submit. To clear it (e.g. after a successful submit), use **FormDraftService** — the same for both reactive and template-driven forms.
122
+
123
+ Inject the service and call `clear(formId)` with the same `formId` you use on the form:
124
+
125
+ ```typescript
126
+ import { FormDraftService } from 'ngx-form-draft';
127
+
128
+ export class MyComponent {
129
+ constructor(private draftService: FormDraftService) {}
130
+
131
+ onSubmit() {
132
+ this.myForm.markAllAsTouched();
133
+ if (this.myForm.invalid) return;
134
+ // ... submit to API ...
135
+ this.draftService.clear('uniqueFormId'); // same id as ngxFormDraft
136
+ }
137
+ }
138
+ ```
139
+
140
+ Users can also clear the draft at any time via the banner’s **Discard** button.
141
+
142
+ ## Internationalization (i18n)
143
+
144
+ The package has **zero dependencies** and supports any i18n solution. Just pass translated strings via inputs:
145
+
146
+ ### With ngx-translate:
147
+ ```html
148
+ <form
149
+ [formGroup]="myForm"
150
+ ngxFormDraft="myForm"
151
+ [draftRestoredText]="'form_draft.restored' | translate"
152
+ [draftSavedText]="'form_draft.saved' | translate"
153
+ [draftSavedLabel]="'form_draft.saved_label' | translate"
154
+ [draftDiscardText]="'form_draft.discard' | translate">
155
+ </form>
156
+ ```
157
+
158
+ ### With Angular i18n:
159
+ ```html
160
+ <form
161
+ [formGroup]="myForm"
162
+ ngxFormDraft="myForm"
163
+ [draftRestoredText]="restoredText"
164
+ [draftSavedText]="savedText"
165
+ [draftDiscardText]="discardText"
166
+ i18n-draftRestoredText="@@formDraftRestored"
167
+ i18n-draftSavedText="@@formDraftSaved"
168
+ i18n-draftDiscardText="@@formDraftDiscard">
169
+ </form>
170
+ ```
171
+
172
+ ### With component properties:
173
+ ```typescript
174
+ // component.ts
175
+ export class MyComponent {
176
+ draftTexts = {
177
+ restored: 'Brouillon restauré',
178
+ saved: 'Brouillon sauvegardé',
179
+ savedLabel: 'sauvegardé',
180
+ discard: 'Supprimer'
181
+ };
182
+ }
183
+ ```
184
+
185
+ ```html
186
+ <!-- template.html -->
187
+ <form
188
+ [formGroup]="myForm"
189
+ ngxFormDraft="myForm"
190
+ [draftRestoredText]="draftTexts.restored"
191
+ [draftSavedText]="draftTexts.saved"
192
+ [draftSavedLabel]="draftTexts.savedLabel"
193
+ [draftDiscardText]="draftTexts.discard">
194
+ </form>
195
+ ```
196
+
197
+ ### Default English text:
198
+ If you don't provide any text inputs, defaults are:
199
+ - `draftRestoredText`: "Draft restored"
200
+ - `draftSavedText`: "Draft saved"
201
+ - `draftSavedLabel`: "saved"
202
+ - `draftDiscardText`: "Discard"
203
+
204
+ ## License
205
+
206
+ MIT