@ng-simplicity/forms-core 1.1.3 → 1.1.5

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 CHANGED
@@ -15,7 +15,7 @@ This core package is extended by styling integration packages that provide prebu
15
15
 
16
16
  | Package | Package version | Angular support |
17
17
  |---|---:|---|
18
- | `@ng-simplicity/forms-core` | `1.1.3` | `17.x`–`22.x` |
18
+ | `@ng-simplicity/forms-core` | `1.1.5` | `17.x`–`22.x` |
19
19
 
20
20
  ---
21
21
 
@@ -46,7 +46,8 @@ Each `registerAll…` helper also registers the core structural components, so i
46
46
  ### 1. The Public Boundary: `NgsFormsService`
47
47
  - Injected by the user's component page.
48
48
  - Exposes form values and statuses through Signals and observables (e.g. `formValue$`, `dirty`, `isValid`).
49
- - Provides entry methods like `setFormConfig(config)` and `patchValue(data)`.
49
+ - Provides entry methods like `setFormConfig(config)`, `patchValue(data)` and `setServerErrorMessages(errors)`.
50
+ - `patchValue(data)` can be called straight after `setFormConfig()`: it keeps the patch and re-applies it as controls render, including fields that the patched values reveal through `visible$`, until the form settles. Form arrays need enough rows (`initialItemCount`).
50
51
  - Implements a retry loading mechanism in case child elements compile asynchronously.
51
52
 
52
53
  ### 2. The Internal Coordinator: `NgsFormsInternalService`
@@ -217,6 +218,18 @@ Each form control component that extends `NgsFormsFormItemWithVisibleAndValidato
217
218
  }
218
219
  ```
219
220
  3. **Displaying Errors**: Within your custom component template, bind your error display element to the `errorMessage` property inherited from the base class. The core engine dynamically updates `errorMessage` based on whether the control is invalid, touched, dirty, or if the form has been submitted.
221
+ 4. **Server Errors**: Pass the server's errors to `NgsFormsService.setServerErrorMessages()` in the same shape as the form value. Each leaf is a key looked up in that field's `errorMessageMap` (a key with no entry is shown as text), and form array rows are matched by index. Each error clears when its field changes, and the call returns the paths that matched no control. `constructServerErrorMessageObject()` builds the object from a list of `{ jsonPath, validator }` pairs:
222
+ ```typescript
223
+ errorMessageMap: { taken: 'User Name Not Available' }
224
+
225
+ this.formsService.setServerErrorMessages({ registration: { userName: 'taken', contacts: [{}, {}, { phone: 'invalidPhone' }] } });
226
+
227
+ // Same thing from a flat list:
228
+ this.formsService.setServerErrorMessages(constructServerErrorMessageObject([
229
+ { jsonPath: 'registration.userName', validator: 'taken' },
230
+ { jsonPath: 'registration.contacts[2].phone', validator: 'invalidPhone' },
231
+ ]));
232
+ ```
220
233
 
221
234
  ---
222
235
 
@@ -397,10 +410,17 @@ import { NgsFormsFormArrayRemoveItemComponent } from '@ng-simplicity/forms-core'
397
410
  const removeContactBtn = NgsFormsFormArrayRemoveItemComponent.create({
398
411
  buttonText: 'Delete',
399
412
  buttonClass: 'btn btn-danger',
400
- buttonIcon: 'trash-icon'
413
+ buttonIcon: 'trash-icon',
414
+ // Optional accessible name. Defaults to `${buttonText} item ${index + 1}`, for example "Delete item 2".
415
+ ariaLabel: (index) => `Delete contact ${index + 1}`,
401
416
  });
402
417
  ```
403
418
 
419
+ The button always removes its own row, even after earlier rows have been removed. When the removed row held the focus, focus moves to the Remove button of the row that takes its place. Custom components inside a row can inject `NGS_FORMS_ARRAY_ROW` (the row's `UntypedFormGroup`) and use `formArray.controls.indexOf(row)` to find the row's current index; `NGS_FORMS_ITEM_INDEX` is the index the row had when it was created.
420
+
421
+ ```typescript
422
+ ```
423
+
404
424
  ### 5. Section (`section`)
405
425
  A visual layout grouping with a title and subtitle.
406
426
  - **Component**: `NgsFormsFormSectionComponent`
@@ -413,6 +433,7 @@ import { NgsFormsFormSectionComponent } from '@ng-simplicity/forms-core';
413
433
  const personalSection = NgsFormsFormSectionComponent.create({
414
434
  title: 'Personal Information',
415
435
  titleClass: 'custom-title-class', // Optional, defaults to 'h3'
436
+ headingLevel: 2, // Optional heading level announced by screen readers, defaults to 3
416
437
  subtitle: 'Tell us a bit about yourself',
417
438
  subtitleClass: 'custom-subtitle-class', // Optional, defaults to 'lead'
418
439
  items: [