@bolttech/form-engine-core 0.0.3-beta.3 → 0.0.3-beta.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/index.esm.js CHANGED
@@ -2497,7 +2497,8 @@ class FormField {
2497
2497
  dataSubject$,
2498
2498
  formValidNotification$,
2499
2499
  mapper,
2500
- getFormValues
2500
+ getFormValues,
2501
+ submitEvent
2501
2502
  }) {
2502
2503
  var _a, _b, _c, _d, _e, _f, _g;
2503
2504
  this.valueSubscription$ = new Subscription();
@@ -2528,6 +2529,7 @@ class FormField {
2528
2529
  this.resetValue = resetValue;
2529
2530
  this.resetProperty = resetProperty;
2530
2531
  this.getFormValues = getFormValues;
2532
+ this.submitEvent = submitEvent;
2531
2533
  this.templateSubject$ = templateSubject$;
2532
2534
  this.fieldEventSubject$ = fieldEventSubject$;
2533
2535
  this.dataSubject$ = dataSubject$;
@@ -2826,6 +2828,9 @@ class FormField {
2826
2828
  emitEvents({
2827
2829
  event
2828
2830
  }) {
2831
+ if (event === 'ON_FORM_SUBMIT') {
2832
+ return this.submitEvent();
2833
+ }
2829
2834
  this.setFieldValidity({
2830
2835
  event
2831
2836
  });
@@ -2893,7 +2898,7 @@ class FormField {
2893
2898
  }
2894
2899
  });
2895
2900
  this.errors = eventMessages;
2896
- } else if (event === 'ON_FORM_SUBMIT') {
2901
+ } else if (event === 'ON_FIELD_VALIDATION') {
2897
2902
  this.errors = errors;
2898
2903
  }
2899
2904
  }
@@ -3125,9 +3130,11 @@ class FormCore {
3125
3130
  */
3126
3131
  const initialValues = entry.initialValues || ((_k = entry.schema) === null || _k === void 0 ? void 0 : _k.initialValues);
3127
3132
  this.fields.forEach((field, key) => {
3133
+ var _a;
3128
3134
  if (!initialValues || initialValues && !Object.keys(initialValues).includes(key)) {
3135
+ const propValue = (_a = field === null || field === void 0 ? void 0 : field.props) === null || _a === void 0 ? void 0 : _a[(field === null || field === void 0 ? void 0 : field.valuePropName) || ''];
3129
3136
  !(field === null || field === void 0 ? void 0 : field.value) && (field === null || field === void 0 ? void 0 : field.emitValue({
3130
- value: '',
3137
+ value: typeof propValue === 'string' && !propValue.includes('${') ? propValue : '',
3131
3138
  event: 'ON_FIELD_MOUNT'
3132
3139
  }));
3133
3140
  }
@@ -3713,7 +3720,7 @@ class FormCore {
3713
3720
  fieldSchema,
3714
3721
  mapperElement
3715
3722
  }) {
3716
- var _a;
3723
+ var _a, _b;
3717
3724
  if (this.fields.has(fieldSchema.name)) {
3718
3725
  throw new Error(`field name ${fieldSchema.name} already defined`);
3719
3726
  }
@@ -3731,7 +3738,8 @@ class FormCore {
3731
3738
  fieldEventSubject$: this.fieldEventSubject$,
3732
3739
  dataSubject$: this.dataSubject$,
3733
3740
  formValidNotification$: this.formValidNotification$,
3734
- config: this.config
3741
+ config: this.config,
3742
+ submitEvent: this.submit.bind(this)
3735
3743
  }));
3736
3744
  this.subscribeTemplates();
3737
3745
  this.refreshTemplates({
@@ -3740,8 +3748,9 @@ class FormCore {
3740
3748
  });
3741
3749
  if (!this.queuedInitialValues.has(fieldSchema.name)) {
3742
3750
  const field = this.fields.get(fieldSchema.name);
3751
+ const propValue = (_b = field === null || field === void 0 ? void 0 : field.props) === null || _b === void 0 ? void 0 : _b[(field === null || field === void 0 ? void 0 : field.valuePropName) || ''];
3743
3752
  !(field === null || field === void 0 ? void 0 : field.value) && (field === null || field === void 0 ? void 0 : field.emitValue({
3744
- value: '',
3753
+ value: typeof propValue === 'string' && !propValue.includes('${') ? propValue : '',
3745
3754
  event: 'ON_FIELD_MOUNT'
3746
3755
  }));
3747
3756
  }
@@ -3792,7 +3801,8 @@ class FormCore {
3792
3801
  dataSubject$: this.dataSubject$,
3793
3802
  formValidNotification$: this.formValidNotification$,
3794
3803
  config: this.config,
3795
- getFormValues: this.getFormValues.bind(this)
3804
+ getFormValues: this.getFormValues.bind(this),
3805
+ submitEvent: this.submit.bind(this)
3796
3806
  }));
3797
3807
  } else {
3798
3808
  currField.children = ((_b = structElement === null || structElement === void 0 ? void 0 : structElement.children) === null || _b === void 0 ? void 0 : _b.map(el => el.name)) || (currField === null || currField === void 0 ? void 0 : currField.children) || [];
@@ -3955,7 +3965,7 @@ class FormCore {
3955
3965
  submit() {
3956
3966
  this.fields.forEach(field => {
3957
3967
  field.emitEvents({
3958
- event: 'ON_FORM_SUBMIT'
3968
+ event: 'ON_FIELD_VALIDATION'
3959
3969
  });
3960
3970
  });
3961
3971
  if (!this.isValid) return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bolttech/form-engine-core",
3
- "version": "0.0.3-beta.3",
3
+ "version": "0.0.3-beta.5",
4
4
  "module": "./index.esm.js",
5
5
  "type": "module",
6
6
  "main": "./index.esm.js",
@@ -71,6 +71,7 @@ declare class FormField {
71
71
  }) => void;
72
72
  getFormValues: () => TFormValues<unknown>;
73
73
  valueChangeEvent: TValueChangeEvent;
74
+ submitEvent: () => void;
74
75
  /**
75
76
  * Creates an instance of FormField.
76
77
  *
@@ -89,7 +90,7 @@ declare class FormField {
89
90
  * @param {TMapper<unknown>} options.mapper, - component generic mapper containing render parameters for adapters
90
91
  * @param {() => TFormValues<unknown>} options.getFormValues, - form instance function that builds onData parameter payload from fields
91
92
  */
92
- constructor({ schemaComponent, config, path, children, validateVisibility, resetValue, resetProperty, templateSubject$, fieldEventSubject$, dataSubject$, formValidNotification$, mapper, getFormValues, }: {
93
+ constructor({ schemaComponent, config, path, children, validateVisibility, resetValue, resetProperty, templateSubject$, fieldEventSubject$, dataSubject$, formValidNotification$, mapper, getFormValues, submitEvent, }: {
93
94
  schemaComponent: IComponentSchema;
94
95
  config?: TSchemaFormConfig;
95
96
  path?: string;
@@ -106,6 +107,7 @@ declare class FormField {
106
107
  event: TEvents;
107
108
  key: string;
108
109
  }) => void;
110
+ submitEvent: () => void;
109
111
  templateSubject$: Subject<TTemplateEvent>;
110
112
  fieldEventSubject$: Subject<TFieldEvent>;
111
113
  dataSubject$: Subject<{
@@ -9,7 +9,7 @@ import { TFormValues } from './form';
9
9
  * const event: TEvents = 'ON_FIELD_CHANGE';
10
10
  * ```
11
11
  */
12
- type TEvents = 'ON_FIELD_MOUNT' | 'ON_FIELD_CHANGE' | 'ON_FIELD_BLUR' | 'ON_FIELD_FOCUS' | 'ON_FIELD_CLICK' | 'ON_FIELD_KEYUP' | 'ON_FIELD_KEYDOWN' | 'ON_FIELD_CLEARED' | 'ON_FORM_SUBMIT' | 'ON_FORM_MOUNT' | 'ON_API_FIELD_RESPONSE';
12
+ type TEvents = 'ON_FIELD_MOUNT' | 'ON_FIELD_CHANGE' | 'ON_FIELD_BLUR' | 'ON_FIELD_FOCUS' | 'ON_FIELD_CLICK' | 'ON_FIELD_KEYUP' | 'ON_FIELD_KEYDOWN' | 'ON_FIELD_CLEARED' | 'ON_FORM_SUBMIT' | 'ON_FIELD_VALIDATION' | 'ON_FORM_MOUNT' | 'ON_API_FIELD_RESPONSE';
13
13
  /**
14
14
  * @type TMutationEvents
15
15
  * Represents the different types of events that can occur internally that triggers templating.
@@ -34,6 +34,7 @@ type TComponentPropsMapping = {
34
34
  setValue?: string;
35
35
  onBlur?: string;
36
36
  onClick?: string;
37
+ onSubmit?: string;
37
38
  onFocus?: string;
38
39
  onKeyUp?: string;
39
40
  onKeyDown?: string;