ngx-vest-forms 2.1.0 → 2.3.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.
- package/README.md +52 -12
- package/fesm2022/ngx-vest-forms.mjs +2225 -1962
- package/fesm2022/ngx-vest-forms.mjs.map +1 -1
- package/package.json +1 -1
- package/types/ngx-vest-forms.d.ts +176 -64
package/README.md
CHANGED
|
@@ -116,7 +116,8 @@ That's all you need. The directive automatically creates controls, wires validat
|
|
|
116
116
|
- **Unidirectional state with signals** — Models are `NgxDeepPartial<T>` so values build up incrementally
|
|
117
117
|
- **Type-safe with runtime shape validation** — Automatic control creation and validation wiring (dev mode checks)
|
|
118
118
|
- **Vest.js validations** — Sync/async, conditional, composable patterns with `only(field)` optimization
|
|
119
|
-
- **Error display modes** — Control when errors show: `on-blur`, `on-submit`,
|
|
119
|
+
- **Error display modes** — Control when errors show: `on-blur`, `on-submit`, `on-blur-or-submit` (default), `on-dirty`, or `always`
|
|
120
|
+
- **Warning display modes** — Control when warnings show: `on-touch`, `on-validated-or-touch` (default), `on-dirty`, or `always`
|
|
120
121
|
- **Form state tracking** — Access touched, dirty, valid/invalid states for individual fields or entire form
|
|
121
122
|
- **Error display helpers** — `ngx-control-wrapper` component (recommended) plus directive building blocks for custom wrappers:
|
|
122
123
|
- `ngx-form-group-wrapper` component (recommended for `ngModelGroup` containers)
|
|
@@ -125,23 +126,60 @@ That's all you need. The directive automatically creates controls, wires validat
|
|
|
125
126
|
- **Cross-field dependencies** — `validationConfig` for field-to-field triggers, `ROOT_FORM` for form-level rules
|
|
126
127
|
- **Utilities** — Field paths, field clearing, validation config builder
|
|
127
128
|
|
|
128
|
-
### Error Display Modes
|
|
129
|
+
### Error & Warning Display Modes
|
|
129
130
|
|
|
130
|
-
Control when validation errors are shown to users with
|
|
131
|
+
Control when validation errors and warnings are shown to users with multiple built-in modes:
|
|
132
|
+
|
|
133
|
+
#### Error Display Modes
|
|
131
134
|
|
|
132
135
|
```typescript
|
|
133
136
|
// Global configuration via DI token
|
|
134
137
|
import { NGX_ERROR_DISPLAY_MODE_TOKEN } from 'ngx-vest-forms';
|
|
135
138
|
|
|
136
139
|
providers: [
|
|
137
|
-
{ provide: NGX_ERROR_DISPLAY_MODE_TOKEN, useValue: 'on-
|
|
140
|
+
{ provide: NGX_ERROR_DISPLAY_MODE_TOKEN, useValue: 'on-dirty' }
|
|
138
141
|
]
|
|
139
142
|
|
|
140
143
|
// Recommended: Use ngx-control-wrapper component
|
|
141
144
|
<ngx-control-wrapper [errorDisplayMode]="'on-blur'">
|
|
142
145
|
<input name="email" [ngModel]="formValue().email" />
|
|
143
146
|
</ngx-control-wrapper>
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
| Mode | Behavior |
|
|
150
|
+
| --------------------- | ---------------------------------------------------- |
|
|
151
|
+
| `'on-blur-or-submit'` | Show after blur OR form submit (default) |
|
|
152
|
+
| `'on-blur'` | Show only after blur/touch |
|
|
153
|
+
| `'on-submit'` | Show only after form submission |
|
|
154
|
+
| `'on-dirty'` | Show as soon as value changes (or after blur/submit) |
|
|
155
|
+
| `'always'` | Show immediately, even on pristine fields |
|
|
156
|
+
|
|
157
|
+
#### Warning Display Modes
|
|
158
|
+
|
|
159
|
+
```typescript
|
|
160
|
+
// Global configuration via DI token
|
|
161
|
+
import { NGX_WARNING_DISPLAY_MODE_TOKEN } from 'ngx-vest-forms';
|
|
162
|
+
|
|
163
|
+
providers: [
|
|
164
|
+
{ provide: NGX_WARNING_DISPLAY_MODE_TOKEN, useValue: 'always' }
|
|
165
|
+
]
|
|
166
|
+
|
|
167
|
+
// Per-instance configuration
|
|
168
|
+
<ngx-control-wrapper [warningDisplayMode]="'on-dirty'">
|
|
169
|
+
<input name="username" [ngModel]="formValue().username" />
|
|
170
|
+
</ngx-control-wrapper>
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
| Mode | Behavior |
|
|
174
|
+
| ------------------------- | ---------------------------------------------------- |
|
|
175
|
+
| `'on-validated-or-touch'` | Show after validation runs or touch (default) |
|
|
176
|
+
| `'on-touch'` | Show only after blur/touch |
|
|
177
|
+
| `'on-dirty'` | Show as soon as value changes (or after blur/submit) |
|
|
178
|
+
| `'always'` | Show immediately, even on pristine fields |
|
|
179
|
+
|
|
180
|
+
#### Group-Safe Mode Example
|
|
144
181
|
|
|
182
|
+
```html
|
|
145
183
|
// Group-safe mode (use this on an ngModelGroup container)
|
|
146
184
|
<ngx-form-group-wrapper ngModelGroup="address">
|
|
147
185
|
<ngx-control-wrapper>
|
|
@@ -172,13 +210,8 @@ For `ngModelGroup` containers, prefer using `<ngx-form-group-wrapper>` (group-sa
|
|
|
172
210
|
- [Accessibility Guide](./docs/ACCESSIBILITY.md)
|
|
173
211
|
- [`ControlWrapperComponent` docs](./projects/ngx-vest-forms/src/lib/components/control-wrapper/README.md)
|
|
174
212
|
|
|
175
|
-
**
|
|
176
|
-
|
|
177
|
-
- **`on-blur-or-submit`** (default) — Show errors after field is touched OR form is submitted
|
|
178
|
-
- **`on-blur`** — Show errors only after field loses focus (touched)
|
|
179
|
-
- **`on-submit`** — Show errors only after form submission
|
|
180
|
-
|
|
181
|
-
**Tip**: Use `on-blur-or-submit` for best UX — users get immediate feedback on touched fields while preventing overwhelming errors on pristine forms.
|
|
213
|
+
> **Styling note**: `ngx-control-wrapper` uses Tailwind CSS utility classes for default styling.
|
|
214
|
+
> If your project doesn't use Tailwind, see the [component docs](./projects/ngx-vest-forms/src/lib/components/control-wrapper/README.md#styling-dependency-tailwind-css) for alternatives.
|
|
182
215
|
|
|
183
216
|
📖 **[Complete Guide: Custom Control Wrappers](./docs/CUSTOM-CONTROL-WRAPPERS.md)**
|
|
184
217
|
|
|
@@ -209,7 +242,14 @@ Access complete form and field state through the `FormErrorDisplayDirective` or
|
|
|
209
242
|
- `isValid()` / `isInvalid()` — Validation state
|
|
210
243
|
- `isPending()` — Async validation in progress
|
|
211
244
|
- `errorMessages()` / `warningMessages()` — Current validation messages
|
|
212
|
-
- `shouldShowErrors()` — Computed based on display mode and state
|
|
245
|
+
- `shouldShowErrors()` / `shouldShowWarnings()` — Computed based on display mode and state
|
|
246
|
+
|
|
247
|
+
**Warnings behavior:**
|
|
248
|
+
|
|
249
|
+
- Warnings are **non-blocking** and do not make a field invalid.
|
|
250
|
+
- They are stored separately from `control.errors` and are cleared on `resetForm()`.
|
|
251
|
+
- These messages may appear after `validationConfig` triggers validation, even if the field was not touched yet.
|
|
252
|
+
- Use `NGX_WARNING_DISPLAY_MODE_TOKEN` to control when warnings display (see [Warning Display Modes](#warning-display-modes)).
|
|
213
253
|
|
|
214
254
|
**Tip**: For async validations, use `createDebouncedPendingState()` to prevent "Validating..." messages from flashing when validation completes quickly (< 200ms).
|
|
215
255
|
|