@stemy/ngx-dynamic-form 19.8.14 → 19.8.15

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.
@@ -550,6 +550,9 @@ async function toWrapOptions(customizeOrOptions, injector, schema, errorMsg) {
550
550
  }
551
551
  return new ConfigForSchemaWrap(schemaOptions, "wrap", injector, schema);
552
552
  }
553
+ function toStringArray(value) {
554
+ return (Array.isArray(value) ? value : String(value || "").split(",")).filter(ObjectUtils.isStringWithValue);
555
+ }
553
556
  function handleConfigs(configs) {
554
557
  return Array.isArray(configs) ? configs : [configs];
555
558
  }
@@ -943,6 +946,7 @@ class DynamicFormBuilderService {
943
946
  const field = {
944
947
  ...this.createFormSerializer(key, data),
945
948
  fieldSet: String(data.fieldSet || ""),
949
+ purposes: toStringArray(data.purposes),
946
950
  priority: isNaN(data.priority) ? Number.MAX_SAFE_INTEGER : Number(data.priority),
947
951
  wrappers: wrappers.filter(ObjectUtils.isDefined),
948
952
  type: data.componentType || type,
@@ -1149,6 +1153,7 @@ class DynamicFormSchemaService {
1149
1153
  layout: property.layout,
1150
1154
  serialize: property.serialize,
1151
1155
  fieldSet: property.fieldSet,
1156
+ purposes: property.purposes || property.purpose,
1152
1157
  priority: property.priority,
1153
1158
  componentType: property.componentType,
1154
1159
  wrappers: wrappers.filter(ObjectUtils.isStringWithValue),
@@ -1512,24 +1517,26 @@ class DynamicFormService {
1512
1517
  group.updateValueAndValidity();
1513
1518
  });
1514
1519
  }
1515
- async serializeForm(form, validate = true) {
1520
+ async serializeForm(form, validate = true, ...purposes) {
1516
1521
  const fields = untracked(() => form.config());
1517
1522
  if (!fields)
1518
1523
  return null;
1519
1524
  if (validate) {
1520
1525
  await this.validateForm(form);
1521
1526
  }
1522
- return this.serialize(fields);
1527
+ return this.serialize(fields, purposes);
1523
1528
  }
1524
- async serialize(fields) {
1529
+ async serialize(fields, purposes = []) {
1525
1530
  const result = {};
1531
+ purposes = purposes ?? [];
1526
1532
  if (!fields)
1527
1533
  return result;
1528
1534
  for (const field of fields) {
1529
1535
  const serializer = field.serializer;
1530
1536
  const key = `${field.key}`;
1531
1537
  const shouldSerialize = field.serialize?.(field, this.injector) ?? field.props?.hidden !== true;
1532
- if (!shouldSerialize) {
1538
+ const includes = purposes.length > 0 ? Array.prototype.includes.bind(field.purposes ?? []) : null;
1539
+ if (!shouldSerialize || (includes && !includes(purposes))) {
1533
1540
  continue;
1534
1541
  }
1535
1542
  if (ObjectUtils.isFunction(serializer)) {
@@ -1538,7 +1545,7 @@ class DynamicFormService {
1538
1545
  }
1539
1546
  const control = field.formControl;
1540
1547
  if (field.fieldGroup) {
1541
- const group = await this.serialize(field.fieldGroup);
1548
+ const group = await this.serialize(field.fieldGroup, purposes);
1542
1549
  if (field.key && !field.asFieldSet) {
1543
1550
  result[key] = !field.fieldArray ? group : Object.values(group);
1544
1551
  continue;
@@ -1847,8 +1854,8 @@ class DynamicFormComponent {
1847
1854
  reset() {
1848
1855
  this.options?.resetModel?.();
1849
1856
  }
1850
- serialize(validate = true) {
1851
- return this.forms.serializeForm(this, validate);
1857
+ serialize(validate = true, ...purposes) {
1858
+ return this.forms.serializeForm(this, validate, ...purposes);
1852
1859
  }
1853
1860
  getField(path) {
1854
1861
  const config = untracked(() => this.config());