@bolttech/form-engine-core 0.0.1-beta.14 → 0.0.1-beta.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.
- package/index.esm.js +8 -6
- package/package.json +1 -1
- package/src/interfaces/schema.d.ts +18 -4
- package/src/types/schema.d.ts +22 -6
package/index.esm.js
CHANGED
|
@@ -2640,7 +2640,7 @@ class FormField {
|
|
|
2640
2640
|
setFieldValidity({
|
|
2641
2641
|
event
|
|
2642
2642
|
}) {
|
|
2643
|
-
var _a, _b;
|
|
2643
|
+
var _a, _b, _c, _d;
|
|
2644
2644
|
if (!this.validations || !this.visibility) {
|
|
2645
2645
|
this.errors = {};
|
|
2646
2646
|
this._valid = true;
|
|
@@ -2666,14 +2666,16 @@ class FormField {
|
|
|
2666
2666
|
}
|
|
2667
2667
|
});
|
|
2668
2668
|
this._valid = valid;
|
|
2669
|
-
if (this.validations.
|
|
2670
|
-
const
|
|
2671
|
-
(
|
|
2669
|
+
if ((_c = (_b = this.validations) === null || _b === void 0 ? void 0 : _b.eventMessages) === null || _c === void 0 ? void 0 : _c[event]) {
|
|
2670
|
+
const eventMessages = {};
|
|
2671
|
+
(_d = this.validations.eventMessages[event]) === null || _d === void 0 ? void 0 : _d.forEach(method => {
|
|
2672
2672
|
if (method in errors) {
|
|
2673
|
-
|
|
2673
|
+
eventMessages[method] = errors[method];
|
|
2674
2674
|
}
|
|
2675
2675
|
});
|
|
2676
|
-
this.errors =
|
|
2676
|
+
this.errors = eventMessages;
|
|
2677
|
+
} else if (event === 'ON_FORM_SUBMIT') {
|
|
2678
|
+
this.errors = errors;
|
|
2677
2679
|
}
|
|
2678
2680
|
}
|
|
2679
2681
|
/**
|
package/package.json
CHANGED
|
@@ -8,10 +8,9 @@ import { TApiEvent, TFormatters, TMasks, TProps, TResetValueMethods, TSchemaForm
|
|
|
8
8
|
* @property {TProps} props - The properties of the component.
|
|
9
9
|
* @property {string} name - The name of the component.
|
|
10
10
|
* @property {string} nameToSubmit - The name of the field when submit values (optional).
|
|
11
|
-
* @property {
|
|
11
|
+
* @property {TValidations} [validations] - The validation methods for the component.
|
|
12
12
|
* @property {TVisibility[]} [visibilityConditions] - The visibility conditions for the component.
|
|
13
13
|
* @property {TResetValueMethods[]} [resetValues] - The reset value methods for the component.
|
|
14
|
-
* @property {TErrorMessages} [errorMessages] - The error messages for the component.
|
|
15
14
|
* @property {TApiEvent} [api] - The API configuration for the component.
|
|
16
15
|
* @property {TFormatters} [formatters] - The formatters for the component.
|
|
17
16
|
* @property {TMasks} [masks] - The masks for the component.
|
|
@@ -24,10 +23,25 @@ import { TApiEvent, TFormatters, TMasks, TProps, TResetValueMethods, TSchemaForm
|
|
|
24
23
|
* props: { type: 'text', placeholder: 'Enter your name' },
|
|
25
24
|
* name: 'name',
|
|
26
25
|
* nameToSubmit: 'applicant.firstName',
|
|
27
|
-
* validations: {
|
|
26
|
+
* validations: {
|
|
27
|
+
* methods: {
|
|
28
|
+
* required: true,
|
|
29
|
+
* regex: '^([0-9]+)*$',
|
|
30
|
+
* max: 5,
|
|
31
|
+
* },
|
|
32
|
+
* eventMessages: {
|
|
33
|
+
* ON_FIELD_MOUNT: ['required'],
|
|
34
|
+
* ON_FIELD_CHANGE: ['regex', 'required'],
|
|
35
|
+
* ON_FIELD_BLUR: ['max', 'required'],
|
|
36
|
+
* },
|
|
37
|
+
* messages: {
|
|
38
|
+
* default: 'This field is required',
|
|
39
|
+
* regex: 'Only numbers are available.',
|
|
40
|
+
* max: 'Max of 5',
|
|
41
|
+
* },
|
|
42
|
+
* },
|
|
28
43
|
* visibilityConditions: [{ conditions: { field: 'age', value: 18 } }],
|
|
29
44
|
* resetValues: [{ field: 'age', resetTo: '' }],
|
|
30
|
-
* errorMessages: { required: 'This field is required.' },
|
|
31
45
|
* api: { defaultConfig: { config: { method: 'POST', url: 'https://api.example.com/submit' }, events: [{ eventName: 'ON_FORM_SUBMIT' }] } },
|
|
32
46
|
* formatters: { capitalize: true },
|
|
33
47
|
* masks: { currency: { align: 'left', decimal: '.', precision: 2, prefix: '$', thousands: ',' } },
|
package/src/types/schema.d.ts
CHANGED
|
@@ -657,19 +657,35 @@ type TApiConfig = {
|
|
|
657
657
|
type TProps = Record<string, unknown>;
|
|
658
658
|
/**
|
|
659
659
|
* @type TValidations
|
|
660
|
-
* Represents the validation
|
|
660
|
+
* Represents the validation configuration for form fields, including methods, event-specific messages, and error messages.
|
|
661
|
+
*
|
|
662
|
+
* @property {TValidationMethods} methods - The validation methods to be applied.
|
|
663
|
+
* @property {Partial<Record<TEvents, string[]>>} eventMessages - The messages to be displayed for specific validation events.
|
|
664
|
+
* @property {TErrorMessages} messages - The general error messages for validation methods.
|
|
661
665
|
*
|
|
662
666
|
* @example
|
|
663
|
-
* ```typescript
|
|
664
667
|
* const validations: TValidations = {
|
|
665
|
-
*
|
|
668
|
+
* methods: {
|
|
669
|
+
* max: 100,
|
|
670
|
+
* required: true,
|
|
671
|
+
* regex: '^[a-zA-Z0-9]+$',
|
|
672
|
+
* },
|
|
673
|
+
* eventMessages: {
|
|
674
|
+
* ON_FIELD_MOUNT: ['required'],
|
|
675
|
+
* ON_FIELD_CHANGE: ['regex', 'required'],
|
|
676
|
+
* ON_FIELD_BLUR: ['max', 'required'],
|
|
677
|
+
* },
|
|
678
|
+
* messages: {
|
|
679
|
+
* default: 'This field is required',
|
|
680
|
+
* max: 'Value exceeds the maximum limit',
|
|
681
|
+
* regex: 'Value does not match the pattern',
|
|
682
|
+
* },
|
|
666
683
|
* };
|
|
667
|
-
* ```
|
|
668
684
|
*/
|
|
669
685
|
type TValidations = {
|
|
670
686
|
methods: TValidationMethods;
|
|
671
|
-
|
|
672
|
-
messages
|
|
687
|
+
eventMessages?: Partial<Record<TEvents, string[]>>;
|
|
688
|
+
messages?: TErrorMessages;
|
|
673
689
|
};
|
|
674
690
|
/**
|
|
675
691
|
* @type TErrorMessages
|