@ngx-formly/core 6.0.0-rc.0 → 6.0.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.
@@ -3,12 +3,16 @@ import { FormlyConfig } from '../services/formly.config';
3
3
  import { FormlyFieldConfig } from '../models';
4
4
  import { FormlyFieldTemplates } from './formly.template';
5
5
  import * as i0 from "@angular/core";
6
+ /**
7
+ * The `<formly-field>` component is used to render the UI widget (layout + type) of a given `field`.
8
+ */
6
9
  export declare class FormlyField implements DoCheck, OnInit, OnChanges, AfterContentInit, AfterViewInit, OnDestroy {
7
10
  private config;
8
11
  private renderer;
9
12
  private _elementRef;
10
13
  private hostContainerRef;
11
14
  private form;
15
+ /** The field config. */
12
16
  field: FormlyFieldConfig;
13
17
  viewContainerRef: ViewContainerRef;
14
18
  private hostObservers;
@@ -5,19 +5,29 @@ import { FormlyFormBuilder } from '../services/formly.builder';
5
5
  import { FormlyConfig } from '../services/formly.config';
6
6
  import { FormlyFieldTemplates, FormlyTemplate } from './formly.template';
7
7
  import * as i0 from "@angular/core";
8
+ /**
9
+ * The `<form-form>` component is the main container of the form,
10
+ * which takes care of managing the form state
11
+ * and delegates the rendering of each field to `<formly-field>` component.
12
+ */
8
13
  export declare class FormlyForm implements DoCheck, OnChanges, OnDestroy {
9
14
  private builder;
10
15
  private config;
11
16
  private ngZone;
12
17
  private fieldTemplates;
18
+ /** The form instance which allow to track model value and validation status. */
13
19
  set form(form: FormGroup | FormArray);
14
20
  get form(): FormGroup | FormArray;
21
+ /** The model to be represented by the form. */
15
22
  set model(model: any);
16
23
  get model(): any;
24
+ /** The field configurations for building the form. */
17
25
  set fields(fieldGroup: FormlyFieldConfig[]);
18
26
  get fields(): FormlyFieldConfig[];
27
+ /** Options for the form. */
19
28
  set options(options: FormlyFormOptions);
20
29
  get options(): FormlyFormOptions;
30
+ /** Event that is emitted when the model value is changed */
21
31
  modelChange: EventEmitter<any>;
22
32
  set templates(templates: QueryList<FormlyTemplate>);
23
33
  field: FormlyFieldConfigCache;
@@ -1,7 +1,9 @@
1
+ import { Type } from '@angular/core';
1
2
  import { ValidationErrors, AbstractControl } from '@angular/forms';
2
- import { FieldType } from './../templates/field.type';
3
- import { FormlyFieldConfig } from './fieldconfig';
4
3
  import { Observable } from 'rxjs';
4
+ import { FormlyFieldConfig } from './fieldconfig';
5
+ import { FieldType } from './../templates/field.type';
6
+ import { FieldWrapper } from '../templates/field.wrapper';
5
7
  export interface FormlyExtension<F extends FormlyFieldConfig = FormlyFieldConfig> {
6
8
  priority?: number;
7
9
  prePopulate?(field: F): void;
@@ -10,14 +12,14 @@ export interface FormlyExtension<F extends FormlyFieldConfig = FormlyFieldConfig
10
12
  }
11
13
  export interface TypeOption {
12
14
  name: string;
13
- component?: any;
15
+ component?: Type<FieldType>;
14
16
  wrappers?: string[];
15
17
  extends?: string;
16
18
  defaultOptions?: FormlyFieldConfig;
17
19
  }
18
20
  export interface WrapperOption {
19
21
  name: string;
20
- component: any;
22
+ component: Type<FieldWrapper>;
21
23
  types?: string[];
22
24
  }
23
25
  export declare type FieldValidatorFn = (c: AbstractControl, field: FormlyFieldConfig, options?: {
@@ -1,4 +1,4 @@
1
- import { FormGroup, FormArray, AbstractControl, FormGroupDirective } from '@angular/forms';
1
+ import { FormGroup, FormArray, AbstractControl, FormGroupDirective, ValidatorFn, AsyncValidatorFn } from '@angular/forms';
2
2
  import { Subject, Observable } from 'rxjs';
3
3
  import { FieldType } from '../templates/field.type';
4
4
  import { FieldWrapper } from '../templates/field.wrapper';
@@ -54,23 +54,13 @@ export interface FormlyFieldConfig<Props = FormlyFieldProps & {
54
54
  * Used to set validation rules for a particular field.
55
55
  * Should be an object of key - value pairs. The value can either be an expression to evaluate or a function to run.
56
56
  * Each should return a boolean value, returning true when the field is valid. See Validation for more information.
57
- *
58
- * {
59
- * validation?: (string | ValidatorFn)[];
60
- * [key: string]: ((control: AbstractControl, field: FormlyFieldConfig) => boolean) | ({ expression: (control: AbstractControl, field: FormlyFieldConfig) => boolean, message: ValidationMessageOption['message'] });
61
- * }
62
57
  */
63
- validators?: any;
58
+ validators?: FormlyValidation<ValidatorFn, boolean>;
64
59
  /**
65
60
  * Use this one for anything that needs to validate asynchronously.
66
61
  * Pretty much exactly the same as the validators api, except it must be a function that returns a promise.
67
- *
68
- * {
69
- * validation?: (string | AsyncValidatorFn)[];
70
- * [key: string]: ((control: AbstractControl, field: FormlyFieldConfig) => Promise<boolean> | Observable<boolean>) | ({ expression: (control: AbstractControl, field: FormlyFieldConfig) => Promise<boolean> | Observable<boolean>, message: string });
71
- * }
72
62
  */
73
- asyncValidators?: any;
63
+ asyncValidators?: FormlyValidation<AsyncValidatorFn, Promise<boolean> | Observable<boolean>>;
74
64
  /**
75
65
  * Can be set instead of `type` to render custom html content.
76
66
  */
@@ -105,7 +95,7 @@ export interface FormlyFieldConfig<Props = FormlyFieldProps & {
105
95
  * An object where the key is a property to be set on the main field config and the value is an expression used to assign that property.
106
96
  */
107
97
  expressions?: {
108
- [property: string]: string | ((field?: FormlyFieldConfig) => any) | Observable<any>;
98
+ [property: string]: string | ((field: FormlyFieldConfig) => any) | Observable<any>;
109
99
  };
110
100
  /**
111
101
  * You can specify your own class that will be applied to the `formly-field` component.
@@ -190,7 +180,7 @@ export interface FormlyFieldProps {
190
180
  /** @deprecated use `minLength` */
191
181
  minlength?: number;
192
182
  maxLength?: number;
193
- /** @deprecated use `minLength` */
183
+ /** @deprecated use `maxLength` */
194
184
  maxlength?: number;
195
185
  pattern?: string | RegExp;
196
186
  required?: boolean;
@@ -233,3 +223,13 @@ export interface FormlyValueChangeEvent {
233
223
  value: any;
234
224
  [meta: string]: any;
235
225
  }
226
+ interface FormlyValidation<T, R> {
227
+ validation?: (string | T)[] | any;
228
+ [key: string]: FormlyValidatorFn<R> | FormlyValidatorExpressionFn<R> | any;
229
+ }
230
+ declare type FormlyValidatorFn<T> = (control: AbstractControl, field: FormlyFieldConfig) => T;
231
+ interface FormlyValidatorExpressionFn<T> {
232
+ expression: FormlyValidatorFn<T>;
233
+ message: string | ((error: any, field: FormlyFieldConfig) => string);
234
+ }
235
+ export {};
@@ -3,9 +3,12 @@ import { FieldType } from './../templates/field.type';
3
3
  import { FormlyFieldConfig, FormlyFieldConfigCache, ConfigOption, TypeOption, ValidatorOption, WrapperOption, FormlyExtension, ValidationMessageOption, FormlyFieldConfigPresetProvider } from '../models';
4
4
  import { FieldWrapper } from '../templates/field.wrapper';
5
5
  import * as i0 from "@angular/core";
6
+ /**
7
+ * An InjectionToken for registering additional formly config options (types, wrappers ...).
8
+ */
6
9
  export declare const FORMLY_CONFIG: InjectionToken<ConfigOption[]>;
7
10
  /**
8
- * Maintains list of formly field directive types. This can be used to register new field templates.
11
+ * Maintains list of formly config options. This can be used to register new field type.
9
12
  */
10
13
  export declare class FormlyConfig {
11
14
  types: {
@@ -29,13 +32,19 @@ export declare class FormlyConfig {
29
32
  };
30
33
  private extensionsByPriority;
31
34
  addConfig(config: ConfigOption): void;
35
+ /**
36
+ * Allows you to specify a custom type which you can use in your field configuration.
37
+ * You can pass an object of options, or an array of objects of options.
38
+ */
32
39
  setType(options: TypeOption | TypeOption[]): void;
33
40
  getType(name: FormlyFieldConfig['type'], throwIfNotFound?: boolean): TypeOption;
41
+ /** @ignore */
34
42
  getMergedField(field?: FormlyFieldConfig): any;
35
- /** @internal */
43
+ /** @ignore @internal */
36
44
  resolveFieldTypeRef(field?: FormlyFieldConfigCache): ComponentRef<FieldType>;
37
45
  setWrapper(options: WrapperOption): void;
38
46
  getWrapper(name: string | Type<FieldWrapper>): WrapperOption;
47
+ /** @ignore */
39
48
  setTypeWrapper(type: string, name: string): void;
40
49
  setValidator(options: ValidatorOption): void;
41
50
  getValidator(name: string): ValidatorOption;
@@ -1,6 +1,7 @@
1
1
  import { DomSanitizer, SafeHtml } from '@angular/platform-browser';
2
2
  import { FieldType } from './field.type';
3
3
  import * as i0 from "@angular/core";
4
+ /** @ignore */
4
5
  export declare class FormlyTemplateType extends FieldType {
5
6
  private sanitizer;
6
7
  get template(): SafeHtml;
@@ -1,9 +1,13 @@
1
1
  import { ElementRef, OnChanges, SimpleChanges, Renderer2, DoCheck, OnDestroy } from '@angular/core';
2
2
  import { FormlyFieldConfig } from '../models';
3
3
  import * as i0 from "@angular/core";
4
+ /**
5
+ * Allow to link the `field` HTML attributes (`id`, `name` ...) and Event attributes (`focus`, `blur` ...) to an element in the DOM.
6
+ */
4
7
  export declare class FormlyAttributes implements OnChanges, DoCheck, OnDestroy {
5
8
  private renderer;
6
9
  private elementRef;
10
+ /** The field config. */
7
11
  field: FormlyFieldConfig;
8
12
  id: string;
9
13
  private document;
@@ -1,5 +1,6 @@
1
1
  import { FieldType, FieldGroupTypeConfig } from './field.type';
2
2
  import * as i0 from "@angular/core";
3
+ /** @ignore */
3
4
  export declare class FormlyGroup extends FieldType<FieldGroupTypeConfig> {
4
5
  static ɵfac: i0.ɵɵFactoryDeclaration<FormlyGroup, never>;
5
6
  static ɵcmp: i0.ɵɵComponentDeclaration<FormlyGroup, "formly-group", never, {}, {}, never, ["*"]>;
@@ -3,8 +3,12 @@ import { FormlyConfig } from '../services/formly.config';
3
3
  import { FormlyFieldConfig } from '../models';
4
4
  import { Observable } from 'rxjs';
5
5
  import * as i0 from "@angular/core";
6
+ /**
7
+ * The `<formly-validation-message>` component renders the error message of a given `field`.
8
+ */
6
9
  export declare class FormlyValidationMessage implements OnChanges {
7
10
  private config;
11
+ /** The field config. */
8
12
  field: FormlyFieldConfig;
9
13
  errorMessage$: Observable<string>;
10
14
  constructor(config: FormlyConfig);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ngx-formly/core",
3
- "version": "6.0.0-rc.0",
3
+ "version": "6.0.0",
4
4
  "license": "MIT",
5
5
  "dependencies": {
6
6
  "tslib": "^2.0.0"