@sumaris-net/ngx-components 2.2.1-rc1 → 2.2.1-rc3

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.
@@ -4216,33 +4216,44 @@ function addValueInArray(arrayControl, createControl, equals, isEmpty, value, op
4216
4216
  * @param values
4217
4217
  */
4218
4218
  function initArrayControlsFromValues(formArray, createControl, defaultValues, options) {
4219
- let hasChanged = false;
4219
+ if (formArray.length === 0 && (!defaultValues || defaultValues.length === 0))
4220
+ return false; // No changes need
4221
+ const disabled = formArray.disabled;
4220
4222
  while (formArray.length > 0) {
4221
4223
  formArray.removeAt(formArray.length - 1, options);
4222
- hasChanged = true;
4223
4224
  }
4224
4225
  (defaultValues || []).forEach(value => {
4225
4226
  const control = createControl(value);
4227
+ // Apply parent disabled state, before to push it into the array
4228
+ // This is need to avoid parent form to be enabled, after calling initArrayControlsFromValues()
4229
+ if (disabled && control.enabled)
4230
+ control.disable({ emitEvent: false });
4231
+ else if (!disabled && control.disabled)
4232
+ control.enable({ emitEvent: false });
4226
4233
  formArray.push(control, options);
4227
- hasChanged = true;
4228
4234
  });
4229
- return hasChanged;
4235
+ return true; // has some changes
4230
4236
  }
4231
4237
  function resizeArray(arrayControl, createControl, length, options) {
4232
- const hasChanged = arrayControl.length !== length;
4233
- // Increase size
4234
- if (arrayControl.length < length) {
4235
- while (arrayControl.length < length) {
4236
- arrayControl.push(createControl(), options);
4237
- }
4238
- }
4239
- // Or reduce
4240
- else if (arrayControl.length > length) {
4241
- while (arrayControl.length > length) {
4242
- arrayControl.removeAt(arrayControl.length - 1, options);
4243
- }
4238
+ if (arrayControl.length === length)
4239
+ return false; // No changes need
4240
+ const disabled = this.formArray.disabled;
4241
+ // Reduce size
4242
+ while (arrayControl.length > length) {
4243
+ arrayControl.removeAt(arrayControl.length - 1, options);
4244
4244
  }
4245
- return hasChanged;
4245
+ // Increase size
4246
+ while (arrayControl.length < length) {
4247
+ const control = createControl();
4248
+ // Apply parent disabled state, before to push it into the array
4249
+ // This is need to avoid parent form to be enabled, after calling resizeArray()
4250
+ if (disabled && control.enabled)
4251
+ control.disable({ emitEvent: false });
4252
+ else if (!disabled && control.disabled)
4253
+ control.enable({ emitEvent: false });
4254
+ arrayControl.push(control, options);
4255
+ }
4256
+ return true; // has some changes
4246
4257
  }
4247
4258
  function removeValueInArray(arrayControl, isEmpty, index) {
4248
4259
  arrayControl.removeAt(index);
@@ -4621,7 +4632,20 @@ class AppFormArray extends UntypedFormArray {
4621
4632
  }
4622
4633
  patchValue(values, options) {
4623
4634
  if (this.options?.resizeStrategy === 'recreate') {
4624
- initArrayControlsFromValues(this, this.createControl, values, options);
4635
+ const disabled = this.disabled;
4636
+ // Clean all
4637
+ this.resize(0, { emitEvent: options?.emitEvent });
4638
+ // Recreate each control, with a default value
4639
+ (values || []).forEach(value => {
4640
+ const control = this.createControl(value);
4641
+ // Apply parent disabled state, before to push it into the array
4642
+ // This is need to avoid parent form to be enabled, after calling AppFormArray.patchValue() (e.g. in table's row validator)
4643
+ if (disabled && control.enabled)
4644
+ control.disable({ emitEvent: false });
4645
+ else if (!disabled && control.disabled)
4646
+ control.enable({ emitEvent: false });
4647
+ this.push(control, options);
4648
+ });
4625
4649
  }
4626
4650
  else {
4627
4651
  this.resize(values?.length || 0, { emitEvent: false });
@@ -4631,28 +4655,21 @@ class AppFormArray extends UntypedFormArray {
4631
4655
  resize(length, options) {
4632
4656
  if (this.length === length)
4633
4657
  return; // Nothing to do
4634
- const enabled = this.enabled; // Save enabled here, because update can occur from resizeArray()
4635
- // Increase size
4636
- if (this.length < length) {
4637
- while (this.length < length) {
4638
- this.push(this.createControl(), { emitEvent: false /*will be done just after, if changes*/ });
4639
- }
4640
- }
4641
- // Or reduce
4642
- else {
4643
- while (this.length > length) {
4644
- this.removeAt(this.length - 1, { emitEvent: false /*will be done just after, if changes*/ });
4645
- }
4646
- }
4647
- // Restore initial status
4648
- // This is a workaround, because push and removeAt can have changed the array status
4649
- if (this.enabled !== enabled) {
4650
- if (enabled) {
4651
- this.enable(options);
4652
- }
4653
- else {
4654
- this.disable(options);
4655
- }
4658
+ const disabled = this.disabled; // Save enabled here, because update can occur from resizeArray()
4659
+ // Reduce
4660
+ while (this.length > length) {
4661
+ this.removeAt(this.length - 1, { emitEvent: options?.emitEvent });
4662
+ }
4663
+ // Or increase size
4664
+ while (this.length < length) {
4665
+ const control = this.createControl();
4666
+ // Apply parent disabled state, before to push it into the array
4667
+ // This is need to avoid parent form to be enabled, after calling AppFormArray.patchValue() (e.g. in table's row validator)
4668
+ if (disabled && control.enabled)
4669
+ control.disable({ emitEvent: false });
4670
+ else if (!disabled && control.disabled)
4671
+ control.enable({ emitEvent: false });
4672
+ this.push(control, options);
4656
4673
  }
4657
4674
  }
4658
4675
  disable(opts) {
@@ -18988,7 +19005,7 @@ class SharedModule {
18988
19005
  ngModule: SharedModule,
18989
19006
  providers: [
18990
19007
  { provide: ENVIRONMENT, useValue: environment },
18991
- { provide: StorageService, useClass: StorageService, deps: [ENVIRONMENT] },
19008
+ // { provide: StorageService, useClass: StorageService, deps: [ENVIRONMENT]},
18992
19009
  { provide: APP_STORAGE, useExisting: StorageService },
18993
19010
  StorageService,
18994
19011
  ProgressBarService,