@sumaris-net/ngx-components 18.16.4 → 18.16.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/doc/changelog.md +4 -0
- package/esm2022/src/app/core/form/array/form-array.mjs +32 -32
- package/esm2022/src/app/shared/forms.mjs +30 -30
- package/fesm2022/sumaris-net.ngx-components.mjs +60 -60
- package/fesm2022/sumaris-net.ngx-components.mjs.map +1 -1
- package/package.json +1 -1
- package/src/app/core/form/array/form-array.d.ts +25 -15
- package/src/app/shared/forms.d.ts +14 -8
- package/src/assets/manifest.json +1 -1
|
@@ -3469,37 +3469,37 @@ class FormArrayHelper {
|
|
|
3469
3469
|
}
|
|
3470
3470
|
/**
|
|
3471
3471
|
* @param value
|
|
3472
|
-
* @param
|
|
3472
|
+
* @param opts
|
|
3473
3473
|
*/
|
|
3474
|
-
add(value,
|
|
3474
|
+
add(value, opts) {
|
|
3475
3475
|
return addValueInArray(this._formArray, this.createControl, this.equals, this.isEmpty, value, {
|
|
3476
3476
|
allowManyNullValues: this.allowManyNullValues,
|
|
3477
3477
|
allowDuplicateValue: this.allowDuplicatedValues,
|
|
3478
|
-
...
|
|
3478
|
+
...opts,
|
|
3479
3479
|
});
|
|
3480
3480
|
}
|
|
3481
|
-
removeAt(index) {
|
|
3481
|
+
removeAt(index, opts) {
|
|
3482
3482
|
// Do not remove if last criterion
|
|
3483
3483
|
if (!this._allowEmptyArray && this._formArray.length === 1) {
|
|
3484
|
-
return clearValueInArray(this._formArray, this.isEmpty, index);
|
|
3484
|
+
return clearValueInArray(this._formArray, this.isEmpty, index, opts);
|
|
3485
3485
|
}
|
|
3486
3486
|
else {
|
|
3487
|
-
return removeValueInArray(this._formArray,
|
|
3487
|
+
return removeValueInArray(this._formArray, index, opts);
|
|
3488
3488
|
}
|
|
3489
3489
|
}
|
|
3490
|
-
resize(length,
|
|
3491
|
-
return resizeArray(this._formArray, this.createControl, length,
|
|
3490
|
+
resize(length, opts) {
|
|
3491
|
+
return resizeArray(this._formArray, this.createControl, length, opts);
|
|
3492
3492
|
}
|
|
3493
|
-
clearAt(index) {
|
|
3494
|
-
return clearValueInArray(this._formArray, this.isEmpty, index);
|
|
3493
|
+
clearAt(index, opts) {
|
|
3494
|
+
return clearValueInArray(this._formArray, this.isEmpty, index, opts);
|
|
3495
3495
|
}
|
|
3496
3496
|
isLast(index) {
|
|
3497
3497
|
return this._formArray.length - 1 === index;
|
|
3498
3498
|
}
|
|
3499
|
-
removeAllEmpty() {
|
|
3499
|
+
removeAllEmpty(opts) {
|
|
3500
3500
|
let index = this._formArray.controls.findIndex((c) => this.isEmpty(c.value));
|
|
3501
3501
|
while (index !== -1) {
|
|
3502
|
-
this.removeAt(index);
|
|
3502
|
+
this.removeAt(index, opts);
|
|
3503
3503
|
index = this._formArray.controls.findIndex((c) => this.isEmpty(c.value));
|
|
3504
3504
|
}
|
|
3505
3505
|
}
|
|
@@ -3523,11 +3523,11 @@ class FormArrayHelper {
|
|
|
3523
3523
|
* Resize the FormArray, then patch values
|
|
3524
3524
|
*
|
|
3525
3525
|
* @param values
|
|
3526
|
-
* @param
|
|
3526
|
+
* @param opts
|
|
3527
3527
|
*/
|
|
3528
|
-
patchValue(values,
|
|
3528
|
+
patchValue(values, opts) {
|
|
3529
3529
|
this.resize(values?.length || 0);
|
|
3530
|
-
this._formArray.patchValue(values,
|
|
3530
|
+
this._formArray.patchValue(values, opts);
|
|
3531
3531
|
}
|
|
3532
3532
|
disable(opts) {
|
|
3533
3533
|
this._formArray.controls.forEach((c) => c.disable(opts));
|
|
@@ -3608,8 +3608,8 @@ class AppFormArray extends UntypedFormArray {
|
|
|
3608
3608
|
// Clean all
|
|
3609
3609
|
this.resize(0, { emitEvent: options?.emitEvent });
|
|
3610
3610
|
// Recreate each control, with a default value
|
|
3611
|
-
(values || []).forEach((value) => {
|
|
3612
|
-
const control = this.createControl(value);
|
|
3611
|
+
(values || []).forEach((value, index) => {
|
|
3612
|
+
const control = this.createControl(value, index);
|
|
3613
3613
|
// Apply parent disabled state, before to push it into the array
|
|
3614
3614
|
// This is need to avoid parent form to be enabled, after calling AppFormArray.patchValue() (e.g. in table's row validator)
|
|
3615
3615
|
if (disabled && control.enabled)
|
|
@@ -3638,8 +3638,8 @@ class AppFormArray extends UntypedFormArray {
|
|
|
3638
3638
|
// Clean all
|
|
3639
3639
|
this.resize(0, { emitEvent: options?.emitEvent });
|
|
3640
3640
|
// Recreate each control, with a default value
|
|
3641
|
-
(values || []).forEach((value) => {
|
|
3642
|
-
const control = this.createControl(value);
|
|
3641
|
+
(values || []).forEach((value, index) => {
|
|
3642
|
+
const control = this.createControl(value, index);
|
|
3643
3643
|
// Apply parent disabled state, before to push it into the array
|
|
3644
3644
|
// This is need to avoid parent form to be enabled, after calling AppFormArray.patchValue() (e.g. in table's row validator)
|
|
3645
3645
|
if (disabled && control.enabled)
|
|
@@ -3675,38 +3675,38 @@ class AppFormArray extends UntypedFormArray {
|
|
|
3675
3675
|
}
|
|
3676
3676
|
/**
|
|
3677
3677
|
* @param value
|
|
3678
|
-
* @param
|
|
3678
|
+
* @param opts
|
|
3679
3679
|
*/
|
|
3680
|
-
add(value,
|
|
3681
|
-
addValueInArray(this, this.createControl, this.equals, this.isEmpty, value, { ...this.options, ...
|
|
3680
|
+
add(value, opts) {
|
|
3681
|
+
addValueInArray(this, this.createControl, this.equals, this.isEmpty, value, { ...this.options, ...opts });
|
|
3682
3682
|
}
|
|
3683
|
-
removeAt(index,
|
|
3683
|
+
removeAt(index, opts) {
|
|
3684
3684
|
// Do not remove if last criterion
|
|
3685
3685
|
if (this.options.allowEmptyArray === false && this.length === 1) {
|
|
3686
|
-
this.clearAt(index,
|
|
3686
|
+
this.clearAt(index, opts);
|
|
3687
3687
|
return false;
|
|
3688
3688
|
}
|
|
3689
3689
|
else if (index < this.length) {
|
|
3690
|
-
super.removeAt(index,
|
|
3691
|
-
this.markAsDirty();
|
|
3690
|
+
super.removeAt(index, opts);
|
|
3691
|
+
this.markAsDirty(opts);
|
|
3692
3692
|
return true;
|
|
3693
3693
|
}
|
|
3694
3694
|
return false;
|
|
3695
3695
|
}
|
|
3696
|
-
clearAt(index,
|
|
3696
|
+
clearAt(index, opts) {
|
|
3697
3697
|
const control = this.at(index);
|
|
3698
3698
|
if (this.isEmpty(control.value))
|
|
3699
3699
|
return; // skip (not need to clear)
|
|
3700
3700
|
if (control instanceof UntypedFormGroup) {
|
|
3701
|
-
copyEntity2Form({}, control,
|
|
3701
|
+
copyEntity2Form({}, control, opts);
|
|
3702
3702
|
}
|
|
3703
3703
|
else if (control instanceof UntypedFormArray) {
|
|
3704
|
-
control.setValue([],
|
|
3704
|
+
control.setValue([], opts);
|
|
3705
3705
|
}
|
|
3706
3706
|
else {
|
|
3707
|
-
control.setValue(null,
|
|
3707
|
+
control.setValue(null, opts);
|
|
3708
3708
|
}
|
|
3709
|
-
this.markAsDirty();
|
|
3709
|
+
this.markAsDirty(opts);
|
|
3710
3710
|
}
|
|
3711
3711
|
isLast(index) {
|
|
3712
3712
|
return this.length - 1 === index;
|
|
@@ -3781,7 +3781,7 @@ function adaptValueToControl(source, control, path) {
|
|
|
3781
3781
|
}
|
|
3782
3782
|
// Resizable array
|
|
3783
3783
|
if (control instanceof AppFormArray) {
|
|
3784
|
-
const exampleControl = control.createControl();
|
|
3784
|
+
const exampleControl = control.createControl(undefined, control.length);
|
|
3785
3785
|
return source.map((item, index) => adaptValueToControl(item, exampleControl, pathPrefix + '#' + index));
|
|
3786
3786
|
}
|
|
3787
3787
|
// Legacy array
|
|
@@ -4074,17 +4074,17 @@ function setControlEnabled(control, enabled, opts) {
|
|
|
4074
4074
|
}
|
|
4075
4075
|
}
|
|
4076
4076
|
}
|
|
4077
|
-
function addValueInArray(arrayControl, createControl, equals, isEmpty, value,
|
|
4077
|
+
function addValueInArray(arrayControl, createControl, equals, isEmpty, value, opts) {
|
|
4078
4078
|
const disabled = arrayControl.disabled;
|
|
4079
4079
|
let hasChanged = false;
|
|
4080
4080
|
let index = -1;
|
|
4081
4081
|
let isEmptyValue = isEmpty(value);
|
|
4082
4082
|
// Search if value already exists
|
|
4083
|
-
if (!isEmptyValue &&
|
|
4083
|
+
if (!isEmptyValue && opts?.allowDuplicateValue !== true) {
|
|
4084
4084
|
index = (arrayControl.value || []).findIndex((v) => equals(value, v));
|
|
4085
4085
|
}
|
|
4086
4086
|
// If value not exists, but last value is empty: reuse last value
|
|
4087
|
-
if (index === -1 &&
|
|
4087
|
+
if (index === -1 && opts?.allowManyNullValues !== true && arrayControl.length > 0) {
|
|
4088
4088
|
const lastValue = arrayControl.at(arrayControl.length - 1).value;
|
|
4089
4089
|
if (isEmpty(lastValue)) {
|
|
4090
4090
|
index = arrayControl.length - 1;
|
|
@@ -4093,31 +4093,31 @@ function addValueInArray(arrayControl, createControl, equals, isEmpty, value, op
|
|
|
4093
4093
|
// Replace the existing value
|
|
4094
4094
|
if (index !== -1) {
|
|
4095
4095
|
if (!isEmptyValue) {
|
|
4096
|
-
arrayControl.at(index).patchValue(value,
|
|
4096
|
+
arrayControl.at(index).patchValue(value, opts);
|
|
4097
4097
|
hasChanged = true;
|
|
4098
4098
|
}
|
|
4099
4099
|
}
|
|
4100
4100
|
else {
|
|
4101
|
-
const control = createControl(value);
|
|
4101
|
+
const control = createControl(value, arrayControl.length);
|
|
4102
4102
|
// Apply parent disabled state, before to push it into the array
|
|
4103
4103
|
// This is need to avoid parent form to be enabled
|
|
4104
4104
|
if (disabled && control.enabled)
|
|
4105
4105
|
control.disable({ emitEvent: false });
|
|
4106
4106
|
else if (!disabled && control.disabled)
|
|
4107
4107
|
control.enable({ emitEvent: false });
|
|
4108
|
-
if (isNotNilOrNaN(
|
|
4109
|
-
arrayControl.insert(
|
|
4108
|
+
if (isNotNilOrNaN(opts?.insertAt)) {
|
|
4109
|
+
arrayControl.insert(opts.insertAt, control, opts);
|
|
4110
4110
|
}
|
|
4111
4111
|
else {
|
|
4112
|
-
arrayControl.push(control,
|
|
4112
|
+
arrayControl.push(control, opts);
|
|
4113
4113
|
}
|
|
4114
4114
|
hasChanged = true;
|
|
4115
4115
|
}
|
|
4116
4116
|
if (hasChanged) {
|
|
4117
|
-
if (!
|
|
4117
|
+
if (!opts || opts.emitEvent !== false) {
|
|
4118
4118
|
// Mark array control dirty
|
|
4119
4119
|
if (!isEmptyValue) {
|
|
4120
|
-
arrayControl.markAsDirty();
|
|
4120
|
+
arrayControl.markAsDirty(opts);
|
|
4121
4121
|
}
|
|
4122
4122
|
}
|
|
4123
4123
|
}
|
|
@@ -4129,67 +4129,67 @@ function addValueInArray(arrayControl, createControl, equals, isEmpty, value, op
|
|
|
4129
4129
|
* @param arrayControl
|
|
4130
4130
|
* @param createControl
|
|
4131
4131
|
* @param defaultValues
|
|
4132
|
-
* @param
|
|
4132
|
+
* @param opts
|
|
4133
4133
|
*/
|
|
4134
|
-
function initArrayControlsFromValues(arrayControl, createControl, defaultValues,
|
|
4134
|
+
function initArrayControlsFromValues(arrayControl, createControl, defaultValues, opts) {
|
|
4135
4135
|
if (arrayControl.length === 0 && (!defaultValues || defaultValues.length === 0))
|
|
4136
4136
|
return false; // No changes need
|
|
4137
4137
|
const disabled = arrayControl.disabled;
|
|
4138
4138
|
while (arrayControl.length > 0) {
|
|
4139
|
-
arrayControl.removeAt(arrayControl.length - 1,
|
|
4139
|
+
arrayControl.removeAt(arrayControl.length - 1, opts);
|
|
4140
4140
|
}
|
|
4141
|
-
(defaultValues || []).forEach((value) => {
|
|
4142
|
-
const control = createControl(value);
|
|
4141
|
+
(defaultValues || []).forEach((value, index) => {
|
|
4142
|
+
const control = createControl(value, index);
|
|
4143
4143
|
// Apply parent disabled state, before to push it into the array
|
|
4144
4144
|
// This is need to avoid parent form to be enabled
|
|
4145
4145
|
if (disabled && control.enabled)
|
|
4146
4146
|
control.disable({ emitEvent: false });
|
|
4147
4147
|
else if (!disabled && control.disabled)
|
|
4148
4148
|
control.enable({ emitEvent: false });
|
|
4149
|
-
arrayControl.push(control,
|
|
4149
|
+
arrayControl.push(control, opts);
|
|
4150
4150
|
});
|
|
4151
4151
|
return true; // Has some changes
|
|
4152
4152
|
}
|
|
4153
|
-
function resizeArray(arrayControl, createControl, length,
|
|
4153
|
+
function resizeArray(arrayControl, createControl, length, opts) {
|
|
4154
4154
|
if (arrayControl.length === length)
|
|
4155
4155
|
return false; // No changes need
|
|
4156
4156
|
const disabled = arrayControl.disabled;
|
|
4157
4157
|
// Reduce size
|
|
4158
4158
|
while (arrayControl.length > length) {
|
|
4159
|
-
arrayControl.removeAt(arrayControl.length - 1,
|
|
4159
|
+
arrayControl.removeAt(arrayControl.length - 1, opts);
|
|
4160
4160
|
}
|
|
4161
4161
|
// Increase size
|
|
4162
4162
|
while (arrayControl.length < length) {
|
|
4163
|
-
const control = createControl();
|
|
4163
|
+
const control = createControl(undefined, arrayControl.length);
|
|
4164
4164
|
// Apply parent disabled state, before to push it into the array
|
|
4165
4165
|
// This is need to avoid parent form to be enabled, after calling resizeArray()
|
|
4166
4166
|
if (disabled && control.enabled)
|
|
4167
4167
|
control.disable({ emitEvent: false });
|
|
4168
4168
|
else if (!disabled && control.disabled)
|
|
4169
4169
|
control.enable({ emitEvent: false });
|
|
4170
|
-
arrayControl.push(control,
|
|
4170
|
+
arrayControl.push(control, opts);
|
|
4171
4171
|
}
|
|
4172
4172
|
return true; // Has some changes
|
|
4173
4173
|
}
|
|
4174
|
-
function removeValueInArray(arrayControl,
|
|
4175
|
-
arrayControl.removeAt(index);
|
|
4176
|
-
arrayControl.markAsDirty();
|
|
4174
|
+
function removeValueInArray(arrayControl, index, opts) {
|
|
4175
|
+
arrayControl.removeAt(index, opts);
|
|
4176
|
+
arrayControl.markAsDirty(opts);
|
|
4177
4177
|
return true;
|
|
4178
4178
|
}
|
|
4179
|
-
function clearValueInArray(arrayControl, isEmpty, index) {
|
|
4179
|
+
function clearValueInArray(arrayControl, isEmpty, index, opts) {
|
|
4180
4180
|
const control = arrayControl.at(index);
|
|
4181
4181
|
if (isEmpty(control.value))
|
|
4182
4182
|
return false; // skip (not need to clear)
|
|
4183
4183
|
if (control instanceof UntypedFormGroup) {
|
|
4184
|
-
copyEntity2Form({}, control);
|
|
4184
|
+
copyEntity2Form({}, control, opts);
|
|
4185
4185
|
}
|
|
4186
4186
|
else if (control instanceof UntypedFormArray) {
|
|
4187
|
-
control.setValue([]);
|
|
4187
|
+
control.setValue([], opts);
|
|
4188
4188
|
}
|
|
4189
4189
|
else {
|
|
4190
|
-
control.setValue(null);
|
|
4190
|
+
control.setValue(null, opts);
|
|
4191
4191
|
}
|
|
4192
|
-
arrayControl.markAsDirty();
|
|
4192
|
+
arrayControl.markAsDirty(opts);
|
|
4193
4193
|
return true;
|
|
4194
4194
|
}
|
|
4195
4195
|
function markAllAsTouched(control, opts) {
|