@olafvv/ngx-dynamic-form 0.2.0 → 0.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.
Files changed (38) hide show
  1. package/README.md +326 -3
  2. package/esm2022/lib/components/dynamic-form/dynamic-form.component.mjs +6 -15
  3. package/esm2022/lib/components/dynamic-form-field/dynamic-form-field.component.mjs +5 -5
  4. package/esm2022/lib/controls/button/dynamic-button.component.mjs +5 -5
  5. package/esm2022/lib/controls/button/dynamic-button.model.mjs +2 -3
  6. package/esm2022/lib/controls/button-toggles/dynamic-button-toggles.component.mjs +6 -6
  7. package/esm2022/lib/controls/checkbox/dynamic-checkbox.component.mjs +3 -3
  8. package/esm2022/lib/controls/input/dynamic-input.component.mjs +6 -6
  9. package/esm2022/lib/controls/input/dynamic-input.model.mjs +2 -1
  10. package/esm2022/lib/controls/radio-group/dynamic-radio-group.component.mjs +6 -6
  11. package/esm2022/lib/controls/readonly/dynamic-readonly.component.mjs +3 -3
  12. package/esm2022/lib/controls/select/dynamic-select.component.mjs +6 -9
  13. package/esm2022/lib/controls/textarea/dynamic-textarea.component.mjs +6 -6
  14. package/esm2022/lib/controls/textarea/dynamic-textarea.model.mjs +2 -1
  15. package/esm2022/lib/models/classes/dynamic-form-field-base.mjs +1 -1
  16. package/esm2022/lib/models/classes/dynamic-form-field-model.mjs +9 -2
  17. package/esm2022/lib/models/classes/dynamic-form-field-option-model.mjs +1 -1
  18. package/esm2022/lib/models/classes/dynamic-form-validators.mjs +21 -21
  19. package/esm2022/lib/models/constants/dynamic-relations.const.mjs +1 -1
  20. package/esm2022/lib/models/interfaces/dynamic-form-field-config.interface.mjs +1 -1
  21. package/esm2022/lib/models/interfaces/dynamic-form-field-relation.interface.mjs +1 -1
  22. package/esm2022/lib/services/dynamic-form-relations.service.mjs +13 -9
  23. package/esm2022/lib/services/dynamic-form.service.mjs +5 -5
  24. package/esm2022/lib/services/dynamic-validations.service.mjs +4 -4
  25. package/fesm2022/olafvv-ngx-dynamic-form.mjs +90 -91
  26. package/fesm2022/olafvv-ngx-dynamic-form.mjs.map +1 -1
  27. package/lib/components/dynamic-form/dynamic-form.component.d.ts +0 -7
  28. package/lib/components/dynamic-form-field/dynamic-form-field.component.d.ts +2 -2
  29. package/lib/controls/button/dynamic-button.model.d.ts +2 -4
  30. package/lib/controls/input/dynamic-input.model.d.ts +2 -0
  31. package/lib/controls/select/dynamic-select.component.d.ts +0 -2
  32. package/lib/controls/textarea/dynamic-textarea.model.d.ts +2 -0
  33. package/lib/models/classes/dynamic-form-field-model.d.ts +3 -1
  34. package/lib/models/classes/dynamic-form-validators.d.ts +12 -12
  35. package/lib/models/constants/dynamic-relations.const.d.ts +9 -1
  36. package/lib/models/interfaces/dynamic-form-field-config.interface.d.ts +7 -2
  37. package/lib/models/interfaces/dynamic-form-field-relation.interface.d.ts +9 -10
  38. package/package.json +1 -1
@@ -2,6 +2,7 @@ import { DynamicFormFieldValueConfig, DynamicFormFieldValueModel } from '../../m
2
2
  export declare const DYNAMIC_FORM_FIELD_TEXTAREA = "textarea";
3
3
  export type DynamicTextareaValue = string | null;
4
4
  export interface DynamicTextareaConfig extends DynamicFormFieldValueConfig<DynamicTextareaValue> {
5
+ placeholder?: string;
5
6
  minLength?: number;
6
7
  maxLength?: number;
7
8
  autocomplete?: 'on' | 'off';
@@ -10,6 +11,7 @@ export interface DynamicTextareaConfig extends DynamicFormFieldValueConfig<Dynam
10
11
  resizeMaxRows?: number;
11
12
  }
12
13
  export declare class DynamicTextarea extends DynamicFormFieldValueModel<DynamicTextareaValue> {
14
+ placeholder: string;
13
15
  minLength: number | null;
14
16
  maxLength: number | null;
15
17
  autocomplete: 'on' | 'off';
@@ -3,7 +3,6 @@ import { DynamicFormFieldConfig } from '../interfaces/dynamic-form-field-config.
3
3
  import { DynamicFormFieldRelation } from '../interfaces/dynamic-form-field-relation.interface';
4
4
  import { DynamicFormValidator } from '../interfaces/dynamic-form-validator.interface';
5
5
  export declare abstract class DynamicFormFieldModel {
6
- hidden: boolean;
7
6
  id: string;
8
7
  width: number;
9
8
  label: string | null;
@@ -15,7 +14,10 @@ export declare abstract class DynamicFormFieldModel {
15
14
  disabledChange: Observable<boolean>;
16
15
  abstract readonly type: string;
17
16
  private readonly disabled$;
17
+ private readonly $hidden;
18
18
  constructor(config: DynamicFormFieldConfig);
19
19
  get disabled(): boolean;
20
20
  set disabled(disable: boolean);
21
+ get hidden(): boolean;
22
+ set hidden(hidden: boolean);
21
23
  }
@@ -1,15 +1,10 @@
1
1
  import { DynamicFormValidator } from '../interfaces/dynamic-form-validator.interface';
2
2
  export declare class DynamicFormValidators {
3
3
  /**
4
- * Default required validator, the control must contain a value
5
- * @param msg
6
- */
7
- static required(msg?: string): DynamicFormValidator;
8
- /**
9
- * Ddefault requiredTrue validator, the value of the control has to be true
4
+ * Default email validator, the value of the control has to be a valid email address
10
5
  * @param msg
11
6
  */
12
- static requiredTrue(msg?: string): DynamicFormValidator;
7
+ static email(msg?: string): DynamicFormValidator;
13
8
  /**
14
9
  * Default min validator, the value has to be greater or equal than the the provided number
15
10
  * @param min number
@@ -34,15 +29,20 @@ export declare class DynamicFormValidators {
34
29
  * @param msg
35
30
  */
36
31
  static maxLength(max: number, msg?: string): DynamicFormValidator;
37
- /**
38
- * Ddefault email validator, the value of the control has to be a valid email address
39
- * @param msg
40
- */
41
- static email(msg?: string): DynamicFormValidator;
42
32
  /**
43
33
  * Default pattern validator, the value of the control has to match the provided pattern
44
34
  * @param pattern: string | RegExp
45
35
  * @param msg
46
36
  */
47
37
  static pattern(pattern: string | RegExp, msg?: string): DynamicFormValidator;
38
+ /**
39
+ * Default required validator, the control must contain a value
40
+ * @param msg
41
+ */
42
+ static required(msg?: string): DynamicFormValidator;
43
+ /**
44
+ * Default requiredTrue validator, the value of the control has to be true
45
+ * @param msg
46
+ */
47
+ static requiredTrue(msg?: string): DynamicFormValidator;
48
48
  }
@@ -1,2 +1,10 @@
1
- import { DynamicRelationAction } from '../interfaces/dynamic-form-field-relation.interface';
1
+ import { Injector } from '@angular/core';
2
+ import { UntypedFormControl } from '@angular/forms';
3
+ import { DynamicFormFieldModel } from '../classes/dynamic-form-field-model';
4
+ import { RelationActionType } from '../interfaces/dynamic-form-field-relation.interface';
5
+ export interface DynamicRelationAction {
6
+ type: RelationActionType;
7
+ reversedType?: string;
8
+ change(hasMatch: boolean, model: DynamicFormFieldModel, control: UntypedFormControl, injector: Injector): void;
9
+ }
2
10
  export declare const RELATION_ACTIONS: DynamicRelationAction[];
@@ -51,8 +51,13 @@ export interface DynamicFormFieldConfig {
51
51
  relations?: DynamicFormFieldRelation[];
52
52
  /**
53
53
  * Event name for the control to update on.
54
- * Possible values: 'change', 'blur' or 'submit'.
55
- * Default values is 'blur'
54
+ * This will determine when Angular is checking the validators
55
+ * Possible values:
56
+ * - `change`: on every change event on the FormControl
57
+ * - `blur`: on the blur event of the FormControl
58
+ * - `submit`: when the parent form of the FormControl is submitted
59
+ *
60
+ * Default value is 'blur'.
56
61
  * @optional
57
62
  */
58
63
  updateOn?: 'submit' | 'blur' | 'change';
@@ -1,6 +1,3 @@
1
- import { Injector } from '@angular/core';
2
- import { UntypedFormControl } from '@angular/forms';
3
- import { DynamicFormFieldModel } from '../classes/dynamic-form-field-model';
4
1
  export declare enum RelationActionType {
5
2
  DISABLED = "DISABLED",
6
3
  ENABLED = "ENABLED",
@@ -14,16 +11,18 @@ export declare enum RelationOperator {
14
11
  OR = "OR"
15
12
  }
16
13
  export interface RelationCondition {
17
- fieldName: string;
14
+ /** Name of a field in the same form this field is depended on */
15
+ fieldName?: string;
16
+ /**
17
+ * Path to the related field.
18
+ * This can be used when working with nested FormGroups and you want to relate a field in a different group.
19
+ * */
20
+ path?: string;
21
+ /** Method that returns true when the condition is met. The passed parameter is the value of the depended field */
18
22
  value: (val: any) => boolean;
19
23
  }
20
24
  export interface DynamicFormFieldRelation {
21
25
  actionType: RelationActionType;
22
- operator?: RelationOperator;
23
26
  conditions: RelationCondition[];
24
- }
25
- export interface DynamicRelationAction {
26
- type: RelationActionType;
27
- reversedType?: string;
28
- change(hasMatch: boolean, model: DynamicFormFieldModel, control: UntypedFormControl, injector: Injector): void;
27
+ operator?: RelationOperator;
29
28
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@olafvv/ngx-dynamic-form",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "peerDependencies": {
5
5
  "@angular/common": "^16.2.12",
6
6
  "@angular/core": "^16.2.12",