@sumaris-net/ngx-components 2.0.9 → 2.1.1
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/esm2020/src/app/core/form/form.utils.mjs +73 -19
- package/fesm2015/sumaris-net.ngx-components.mjs +72 -18
- package/fesm2015/sumaris-net.ngx-components.mjs.map +1 -1
- package/fesm2020/sumaris-net.ngx-components.mjs +72 -18
- package/fesm2020/sumaris-net.ngx-components.mjs.map +1 -1
- package/package.json +1 -1
- package/src/app/core/form/form.utils.d.ts +38 -10
|
@@ -4496,9 +4496,6 @@ class FormArrayHelper {
|
|
|
4496
4496
|
}
|
|
4497
4497
|
return arrayControl;
|
|
4498
4498
|
}
|
|
4499
|
-
static hasHelper(formArray) {
|
|
4500
|
-
return formArray && !!formArray[AppFormArray.HELPER_PROPERTY];
|
|
4501
|
-
}
|
|
4502
4499
|
get allowEmptyArray() {
|
|
4503
4500
|
return this._allowEmptyArray;
|
|
4504
4501
|
}
|
|
@@ -4588,16 +4585,19 @@ class FormArrayHelper {
|
|
|
4588
4585
|
}
|
|
4589
4586
|
}
|
|
4590
4587
|
class AppFormArray extends UntypedFormArray {
|
|
4591
|
-
constructor(
|
|
4592
|
-
super(
|
|
4588
|
+
constructor(createControl, equals, isEmpty, options) {
|
|
4589
|
+
super([], options); // empty array not allow by default
|
|
4590
|
+
this.createControl = createControl;
|
|
4591
|
+
this.equals = equals;
|
|
4592
|
+
this.isEmpty = isEmpty;
|
|
4593
|
+
this.options = options;
|
|
4594
|
+
this.setAllowEmptyArray(toBoolean(options && options.allowEmptyArray, false));
|
|
4593
4595
|
}
|
|
4594
|
-
|
|
4595
|
-
this.
|
|
4596
|
-
return this;
|
|
4596
|
+
get allowEmptyArray() {
|
|
4597
|
+
return this._allowEmptyArray;
|
|
4597
4598
|
}
|
|
4598
|
-
|
|
4599
|
-
this.
|
|
4600
|
-
return this;
|
|
4599
|
+
set allowEmptyArray(value) {
|
|
4600
|
+
this.setAllowEmptyArray(value);
|
|
4601
4601
|
}
|
|
4602
4602
|
/**
|
|
4603
4603
|
* WIll rebuild the array, using the given values
|
|
@@ -4605,19 +4605,73 @@ class AppFormArray extends UntypedFormArray {
|
|
|
4605
4605
|
* @param options
|
|
4606
4606
|
*/
|
|
4607
4607
|
setValue(values, options) {
|
|
4608
|
-
|
|
4609
|
-
|
|
4608
|
+
setValueInArray(this, this.createControl, values);
|
|
4609
|
+
}
|
|
4610
|
+
enable(opts) {
|
|
4611
|
+
this.controls.forEach(c => c.enable(opts));
|
|
4612
|
+
}
|
|
4613
|
+
forEach(ite) {
|
|
4614
|
+
const size = this.length;
|
|
4615
|
+
for (let i = 0; i < size; i++) {
|
|
4616
|
+
const control = this.at(i);
|
|
4617
|
+
if (control)
|
|
4618
|
+
ite(control);
|
|
4610
4619
|
}
|
|
4611
|
-
this._helper.setValue(values, options);
|
|
4612
4620
|
}
|
|
4613
4621
|
resize(length) {
|
|
4614
|
-
|
|
4615
|
-
|
|
4622
|
+
return resizeArray(this, this.createControl, length);
|
|
4623
|
+
}
|
|
4624
|
+
/**
|
|
4625
|
+
* @param value
|
|
4626
|
+
* @param options
|
|
4627
|
+
* @deprecated Use push() instead
|
|
4628
|
+
*/
|
|
4629
|
+
add(value, options) {
|
|
4630
|
+
return pushValueInArray(this, this.createControl, this.equals, this.isEmpty, value, options);
|
|
4631
|
+
}
|
|
4632
|
+
push(value, options) {
|
|
4633
|
+
return pushValueInArray(this, () => this.createControl(value), this.equals, this.isEmpty, value, options);
|
|
4634
|
+
}
|
|
4635
|
+
removeAt(index) {
|
|
4636
|
+
// Do not remove if last criterion
|
|
4637
|
+
if (!this._allowEmptyArray && this.length === 1) {
|
|
4638
|
+
return clearValueInArray(this, this.isEmpty, index);
|
|
4639
|
+
}
|
|
4640
|
+
else {
|
|
4641
|
+
return removeValueInArray(this, this.isEmpty, index);
|
|
4642
|
+
}
|
|
4643
|
+
}
|
|
4644
|
+
clearAt(index) {
|
|
4645
|
+
return clearValueInArray(this, this.isEmpty, index);
|
|
4646
|
+
}
|
|
4647
|
+
isLast(index) {
|
|
4648
|
+
return (this.length - 1) === index;
|
|
4649
|
+
}
|
|
4650
|
+
removeAllEmpty() {
|
|
4651
|
+
let index = this.controls.findIndex(c => this.isEmpty(c.value));
|
|
4652
|
+
while (index !== -1) {
|
|
4653
|
+
this.removeAt(index);
|
|
4654
|
+
index = this.controls.findIndex(c => this.isEmpty(c.value));
|
|
4655
|
+
}
|
|
4656
|
+
}
|
|
4657
|
+
disable(opts) {
|
|
4658
|
+
this.controls.forEach(c => c.disable(opts));
|
|
4659
|
+
}
|
|
4660
|
+
/* -- internal -- */
|
|
4661
|
+
setAllowEmptyArray(value) {
|
|
4662
|
+
if (this._allowEmptyArray === value)
|
|
4663
|
+
return; // Skip if same
|
|
4664
|
+
this._allowEmptyArray = value;
|
|
4665
|
+
// Set required (or reste) min length validator
|
|
4666
|
+
if (this._allowEmptyArray) {
|
|
4667
|
+
this.setValidators(this.options.validators || null);
|
|
4668
|
+
}
|
|
4669
|
+
else {
|
|
4670
|
+
const validators = Array.isArray(this.options.validators) ? this.options.validators : (this.options.validators ? [this.options.validators] : []);
|
|
4671
|
+
this.setValidators(validators.concat(SharedFormArrayValidators.requiredArrayMinLength(1)));
|
|
4616
4672
|
}
|
|
4617
|
-
this._helper.resize(length);
|
|
4618
4673
|
}
|
|
4619
4674
|
}
|
|
4620
|
-
AppFormArray.HELPER_PROPERTY = '_helper';
|
|
4621
4675
|
// TODO continue to use this kind of declaration ?
|
|
4622
4676
|
class AppFormUtils {
|
|
4623
4677
|
static isForm(object) {
|