@breadstone/mosaik-elements-angular 0.0.186 → 0.0.188

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/CHANGELOG.md CHANGED
@@ -1,3 +1,18 @@
1
+ ## 0.0.188 (2025-12-02)
2
+
3
+ ### 🚀 Features
4
+
5
+ - **directives:** update FormFieldDirective to improve error handling and usage documentation ([7c07bb43fd](https://github.com/RueDeRennes/mosaik/commit/7c07bb43fd))
6
+
7
+ ### 🩹 Fixes
8
+
9
+ - **directives:** rename applyError to setError for clarity in FormFieldDirective ([747560c657](https://github.com/RueDeRennes/mosaik/commit/747560c657))
10
+ - **directives:** enhance error handling in FormFieldDirective to check for invalid state ([3b098ac14c](https://github.com/RueDeRennes/mosaik/commit/3b098ac14c))
11
+
12
+ ## 0.0.187 (2025-12-02)
13
+
14
+ This was a version bump only for mosaik-elements-angular to align it with other projects, there were no code changes.
15
+
1
16
  ## 0.0.186 (2025-12-02)
2
17
 
3
18
  ### 🚀 Features
@@ -61727,72 +61727,88 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.1", ngImpor
61727
61727
  args: [{ required: true }]
61728
61728
  }] } });
61729
61729
 
61730
- // #region Imports
61731
- // #endregion
61730
+ //#region Imports
61731
+ //#endregion
61732
61732
  /**
61733
- * Directive for binding Signal Form validation errors to mosaik-form-field elements.
61734
- * Automatically sets the native error property with the first validation error message.
61733
+ * Attribute-Directive that binds a `FieldState` to `FormFieldElement`.
61734
+ * It observes the validation `errors()` and `touched()` state of the field,
61735
+ * and automatically updates the Element’s `error` property — always using the **last** validation error (if any) when the field has been touched.
61735
61736
  *
61736
61737
  * @public
61737
- *
61738
- * @example
61738
+ * @Usage
61739
61739
  * ```html
61740
- * <mosaik-form-field [error]="emailField">
61741
- * <input type="email" [value]="emailField.value()" />
61740
+ * <mosaik-form-field [fieldState]="form.someField()">
61741
+ * <mosaik-textbox [field]="form.someField" />
61742
61742
  * </mosaik-form-field>
61743
61743
  * ```
61744
61744
  */
61745
61745
  class FormFieldDirective {
61746
- // #region Fields
61746
+ //#region Fields
61747
61747
  _elementRef;
61748
- // #endregion
61749
- // #region Ctor
61750
- /**
61751
- * Constructs a new instance of the `{@link FormFieldErrorDirective}` class.
61752
- *
61753
- * @public
61754
- */
61755
- constructor(elementRef = inject(ElementRef)) {
61748
+ //#endregion
61749
+ //#region Ctor
61750
+ constructor(elementRef = inject((ElementRef))) {
61756
61751
  this._elementRef = elementRef;
61752
+ // Observe changes in the fieldState signal. Whenever it changes (value, errors, touched…),
61753
+ // we recalc the error message and apply it to the Web Component.
61757
61754
  effect(() => {
61758
- const fieldState = this.field();
61759
- this.updateErrorProperty(fieldState);
61755
+ const fs = this.fieldState();
61756
+ this.setError(fs);
61760
61757
  });
61761
61758
  }
61762
- // #endregion
61763
- field = input.required({ ...(ngDevMode ? { debugName: "field" } : {}) });
61764
- // #region Methods
61759
+ //#endregion
61760
+ //#region Properties
61765
61761
  /**
61766
- * Updates the error property of the form field element based on the provided FieldState.
61762
+ * The FieldState to observe for validation errors.
61767
61763
  *
61768
- * @private
61769
- * @param fieldState The FieldState containing validation information.
61764
+ * @required
61765
+ * @public
61766
+ * @example
61767
+ * ```html
61768
+ * <mosaik-form-field [fieldState]="form.someField()">
61769
+ * …
61770
+ * </mosaik-form-field>
61771
+ * ```
61772
+ */
61773
+ fieldState = input.required({ ...(ngDevMode ? { debugName: "fieldState" } : {}) });
61774
+ //#endregion
61775
+ //#region Methods
61776
+ /**
61777
+ * Maps the FieldState (errors + touched) to the Element error property.
61778
+ * If there is at least one error AND the field has been touched → set error to the
61779
+ * last error.message. Otherwise clear the error.
61780
+ *
61781
+ * @param fieldState The current FieldState
61770
61782
  */
61771
- updateErrorProperty(fieldState) {
61772
- const element = this._elementRef.nativeElement;
61783
+ setError(fieldState) {
61784
+ const el = this._elementRef.nativeElement;
61773
61785
  if (!fieldState) {
61774
- element.error = '';
61786
+ el.error = '';
61775
61787
  return;
61776
61788
  }
61777
- const errors = fieldState.errors();
61778
- if (errors.length > 0 && fieldState.touched()) {
61779
- const firstError = errors[0];
61780
- const errorMessage = firstError.message;
61781
- element.error = errorMessage ?? '';
61789
+ const errors = fieldState.errors(); // array of validation errors
61790
+ const isTouched = fieldState.touched(); // whether the field was touched
61791
+ const isInvalid = fieldState.invalid(); // whether the field is invalid
61792
+ if (errors.length > 0 && isTouched && isInvalid) {
61793
+ // Use the last error in the array as the “active” error message
61794
+ const lastError = errors[errors.length - 1];
61795
+ el.error = lastError.message ?? '';
61782
61796
  }
61783
61797
  else {
61784
- element.error = '';
61798
+ // No errors or not touched yet → clear error
61799
+ el.error = '';
61785
61800
  }
61786
61801
  }
61787
61802
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.1", ngImport: i0, type: FormFieldDirective, deps: [{ token: i0.ElementRef }], target: i0.ɵɵFactoryTarget.Directive });
61788
- static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.0.1", type: FormFieldDirective, isStandalone: true, selector: "mosaik-form-field[field]", inputs: { field: { classPropertyName: "field", publicName: "field", isSignal: true, isRequired: true, transformFunction: null } }, ngImport: i0 });
61803
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.0.1", type: FormFieldDirective, isStandalone: true, selector: "mosaik-form-field", inputs: { fieldState: { classPropertyName: "fieldState", publicName: "fieldState", isSignal: true, isRequired: true, transformFunction: null } }, ngImport: i0 });
61789
61804
  }
61790
61805
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.1", ngImport: i0, type: FormFieldDirective, decorators: [{
61791
61806
  type: Directive,
61792
61807
  args: [{
61793
- selector: 'mosaik-form-field[field]'
61808
+ // applies to your custom element
61809
+ selector: 'mosaik-form-field'
61794
61810
  }]
61795
- }], ctorParameters: () => [{ type: i0.ElementRef }], propDecorators: { field: [{ type: i0.Input, args: [{ isSignal: true, alias: "field", required: true }] }] } });
61811
+ }], ctorParameters: () => [{ type: i0.ElementRef }], propDecorators: { fieldState: [{ type: i0.Input, args: [{ isSignal: true, alias: "fieldState", required: true }] }] } });
61796
61812
 
61797
61813
  // #region Imports
61798
61814
  // #endregion