@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.
- package/README.md +11 -11
- package/esm2020/lib/components/formly.field.mjs +5 -2
- package/esm2020/lib/components/formly.form.mjs +11 -1
- package/esm2020/lib/extensions/field-form/field-form.mjs +10 -2
- package/esm2020/lib/models/config.mjs +1 -1
- package/esm2020/lib/models/fieldconfig.mjs +1 -1
- package/esm2020/lib/services/formly.config.mjs +12 -3
- package/esm2020/lib/templates/field-template.type.mjs +2 -1
- package/esm2020/lib/templates/formly.attributes.mjs +6 -3
- package/esm2020/lib/templates/formly.group.mjs +2 -1
- package/esm2020/lib/templates/formly.validation-message.mjs +4 -1
- package/fesm2015/ngx-formly-core.mjs +43 -5
- package/fesm2015/ngx-formly-core.mjs.map +1 -1
- package/fesm2020/ngx-formly-core.mjs +43 -5
- package/fesm2020/ngx-formly-core.mjs.map +1 -1
- package/lib/components/formly.field.d.ts +4 -0
- package/lib/components/formly.form.d.ts +10 -0
- package/lib/models/config.d.ts +6 -4
- package/lib/models/fieldconfig.d.ts +15 -15
- package/lib/services/formly.config.d.ts +11 -2
- package/lib/templates/field-template.type.d.ts +1 -0
- package/lib/templates/formly.attributes.d.ts +4 -0
- package/lib/templates/formly.group.d.ts +1 -0
- package/lib/templates/formly.validation-message.d.ts +4 -0
- package/package.json +1 -1
|
@@ -281,9 +281,12 @@ function markFieldForCheck(field) {
|
|
|
281
281
|
});
|
|
282
282
|
}
|
|
283
283
|
|
|
284
|
+
/**
|
|
285
|
+
* An InjectionToken for registering additional formly config options (types, wrappers ...).
|
|
286
|
+
*/
|
|
284
287
|
const FORMLY_CONFIG = new InjectionToken('FORMLY_CONFIG');
|
|
285
288
|
/**
|
|
286
|
-
* Maintains list of formly
|
|
289
|
+
* Maintains list of formly config options. This can be used to register new field type.
|
|
287
290
|
*/
|
|
288
291
|
class FormlyConfig {
|
|
289
292
|
constructor() {
|
|
@@ -331,6 +334,10 @@ class FormlyConfig {
|
|
|
331
334
|
};
|
|
332
335
|
}
|
|
333
336
|
}
|
|
337
|
+
/**
|
|
338
|
+
* Allows you to specify a custom type which you can use in your field configuration.
|
|
339
|
+
* You can pass an object of options, or an array of objects of options.
|
|
340
|
+
*/
|
|
334
341
|
setType(options) {
|
|
335
342
|
if (Array.isArray(options)) {
|
|
336
343
|
options.forEach((option) => this.setType(option));
|
|
@@ -359,6 +366,7 @@ class FormlyConfig {
|
|
|
359
366
|
this.mergeExtendedType(name);
|
|
360
367
|
return this.types[name];
|
|
361
368
|
}
|
|
369
|
+
/** @ignore */
|
|
362
370
|
getMergedField(field = {}) {
|
|
363
371
|
const type = this.getType(field.type);
|
|
364
372
|
if (!type) {
|
|
@@ -387,7 +395,7 @@ class FormlyConfig {
|
|
|
387
395
|
field.wrappers = [...type.wrappers];
|
|
388
396
|
}
|
|
389
397
|
}
|
|
390
|
-
/** @internal */
|
|
398
|
+
/** @ignore @internal */
|
|
391
399
|
resolveFieldTypeRef(field = {}) {
|
|
392
400
|
const type = this.getType(field.type);
|
|
393
401
|
if (!type) {
|
|
@@ -422,6 +430,7 @@ class FormlyConfig {
|
|
|
422
430
|
}
|
|
423
431
|
return this.wrappers[name];
|
|
424
432
|
}
|
|
433
|
+
/** @ignore */
|
|
425
434
|
setTypeWrapper(type, name) {
|
|
426
435
|
if (!this.types[type]) {
|
|
427
436
|
this.types[type] = {};
|
|
@@ -697,6 +706,9 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.11", ngImpo
|
|
|
697
706
|
type: Injectable
|
|
698
707
|
}] });
|
|
699
708
|
|
|
709
|
+
/**
|
|
710
|
+
* The `<formly-field>` component is used to render the UI widget (layout + type) of a given `field`.
|
|
711
|
+
*/
|
|
700
712
|
class FormlyField {
|
|
701
713
|
constructor(config, renderer, _elementRef, hostContainerRef, form) {
|
|
702
714
|
this.config = config;
|
|
@@ -875,7 +887,7 @@ class FormlyField {
|
|
|
875
887
|
}
|
|
876
888
|
const subscribes = [
|
|
877
889
|
observeDeep(field, ['props'], () => field.options.detectChanges(field)),
|
|
878
|
-
observeDeep(field, ['
|
|
890
|
+
observeDeep(field.options, ['formState'], () => field.options.detectChanges(field)),
|
|
879
891
|
];
|
|
880
892
|
for (const path of [['template'], ['fieldGroupClassName'], ['validation', 'show']]) {
|
|
881
893
|
const fieldObserver = observe(field, path, ({ firstChange }) => !firstChange && field.options.detectChanges(field));
|
|
@@ -933,35 +945,45 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.11", ngImpo
|
|
|
933
945
|
args: ['container', { read: ViewContainerRef, static: true }]
|
|
934
946
|
}] } });
|
|
935
947
|
|
|
948
|
+
/**
|
|
949
|
+
* The `<form-form>` component is the main container of the form,
|
|
950
|
+
* which takes care of managing the form state
|
|
951
|
+
* and delegates the rendering of each field to `<formly-field>` component.
|
|
952
|
+
*/
|
|
936
953
|
class FormlyForm {
|
|
937
954
|
constructor(builder, config, ngZone, fieldTemplates) {
|
|
938
955
|
this.builder = builder;
|
|
939
956
|
this.config = config;
|
|
940
957
|
this.ngZone = ngZone;
|
|
941
958
|
this.fieldTemplates = fieldTemplates;
|
|
959
|
+
/** Event that is emitted when the model value is changed */
|
|
942
960
|
this.modelChange = new EventEmitter();
|
|
943
961
|
this.field = { type: 'formly-group' };
|
|
944
962
|
this._modelChangeValue = {};
|
|
945
963
|
this.valueChangesUnsubscribe = () => { };
|
|
946
964
|
}
|
|
965
|
+
/** The form instance which allow to track model value and validation status. */
|
|
947
966
|
set form(form) {
|
|
948
967
|
this.field.form = form;
|
|
949
968
|
}
|
|
950
969
|
get form() {
|
|
951
970
|
return this.field.form;
|
|
952
971
|
}
|
|
972
|
+
/** The model to be represented by the form. */
|
|
953
973
|
set model(model) {
|
|
954
974
|
this.setField({ model });
|
|
955
975
|
}
|
|
956
976
|
get model() {
|
|
957
977
|
return this.field.model;
|
|
958
978
|
}
|
|
979
|
+
/** The field configurations for building the form. */
|
|
959
980
|
set fields(fieldGroup) {
|
|
960
981
|
this.setField({ fieldGroup });
|
|
961
982
|
}
|
|
962
983
|
get fields() {
|
|
963
984
|
return this.field.fieldGroup;
|
|
964
985
|
}
|
|
986
|
+
/** Options for the form. */
|
|
965
987
|
set options(options) {
|
|
966
988
|
this.setField({ options });
|
|
967
989
|
}
|
|
@@ -1038,6 +1060,9 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.11", ngImpo
|
|
|
1038
1060
|
args: [FormlyTemplate]
|
|
1039
1061
|
}] } });
|
|
1040
1062
|
|
|
1063
|
+
/**
|
|
1064
|
+
* Allow to link the `field` HTML attributes (`id`, `name` ...) and Event attributes (`focus`, `blur` ...) to an element in the DOM.
|
|
1065
|
+
*/
|
|
1041
1066
|
class FormlyAttributes {
|
|
1042
1067
|
constructor(renderer, elementRef, _document) {
|
|
1043
1068
|
this.renderer = renderer;
|
|
@@ -1148,10 +1173,10 @@ class FormlyAttributes {
|
|
|
1148
1173
|
const isFocused = !!this.document.activeElement &&
|
|
1149
1174
|
this.fieldAttrElements.some(({ nativeElement }) => this.document.activeElement === nativeElement || nativeElement.contains(this.document.activeElement));
|
|
1150
1175
|
if (value && !isFocused) {
|
|
1151
|
-
element.nativeElement.focus();
|
|
1176
|
+
Promise.resolve().then(() => element.nativeElement.focus());
|
|
1152
1177
|
}
|
|
1153
1178
|
else if (!value && isFocused) {
|
|
1154
|
-
element.nativeElement.blur();
|
|
1179
|
+
Promise.resolve().then(() => element.nativeElement.blur());
|
|
1155
1180
|
}
|
|
1156
1181
|
}
|
|
1157
1182
|
onFocus($event) {
|
|
@@ -1258,6 +1283,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.11", ngImpo
|
|
|
1258
1283
|
type: Input
|
|
1259
1284
|
}] } });
|
|
1260
1285
|
|
|
1286
|
+
/** @ignore */
|
|
1261
1287
|
class FormlyGroup extends FieldType {
|
|
1262
1288
|
}
|
|
1263
1289
|
FormlyGroup.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.11", ngImport: i0, type: FormlyGroup, deps: null, target: i0.ɵɵFactoryTarget.Component });
|
|
@@ -1280,6 +1306,9 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.11", ngImpo
|
|
|
1280
1306
|
}]
|
|
1281
1307
|
}] });
|
|
1282
1308
|
|
|
1309
|
+
/**
|
|
1310
|
+
* The `<formly-validation-message>` component renders the error message of a given `field`.
|
|
1311
|
+
*/
|
|
1283
1312
|
class FormlyValidationMessage {
|
|
1284
1313
|
constructor(config) {
|
|
1285
1314
|
this.config = config;
|
|
@@ -1410,6 +1439,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.11", ngImpo
|
|
|
1410
1439
|
args: ['fieldComponent', { read: ViewContainerRef, static: true }]
|
|
1411
1440
|
}] } });
|
|
1412
1441
|
|
|
1442
|
+
/** @ignore */
|
|
1413
1443
|
class FormlyTemplateType extends FieldType {
|
|
1414
1444
|
constructor(sanitizer) {
|
|
1415
1445
|
super();
|
|
@@ -1921,6 +1951,14 @@ class FieldFormExtension {
|
|
|
1921
1951
|
}
|
|
1922
1952
|
if (markForCheck) {
|
|
1923
1953
|
updateValidity(c, true);
|
|
1954
|
+
// update validity of `FormGroup` instance created by field with nested key.
|
|
1955
|
+
let parent = c.parent;
|
|
1956
|
+
for (let i = 1; i < getKeyPath(field).length; i++) {
|
|
1957
|
+
if (parent) {
|
|
1958
|
+
updateValidity(parent, true);
|
|
1959
|
+
parent = parent.parent;
|
|
1960
|
+
}
|
|
1961
|
+
}
|
|
1924
1962
|
}
|
|
1925
1963
|
}
|
|
1926
1964
|
}
|