structured-fw 1.0.1 → 1.0.2
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.
|
@@ -2,6 +2,7 @@ import { FormValidationEntry, PostedDataDecoded, ValidationResult, ValidationRul
|
|
|
2
2
|
export declare class FormValidation {
|
|
3
3
|
fieldRules: Array<FormValidationEntry>;
|
|
4
4
|
singleError: boolean;
|
|
5
|
+
customValidators: Array<string>;
|
|
5
6
|
validators: {
|
|
6
7
|
[name: string]: ValidatorFunction;
|
|
7
8
|
};
|
|
@@ -2,6 +2,7 @@ export class FormValidation {
|
|
|
2
2
|
constructor() {
|
|
3
3
|
this.fieldRules = [];
|
|
4
4
|
this.singleError = false;
|
|
5
|
+
this.customValidators = [];
|
|
5
6
|
this.validators = {
|
|
6
7
|
'required': async (data, field) => {
|
|
7
8
|
if (!(field in data)) {
|
|
@@ -124,6 +125,7 @@ export class FormValidation {
|
|
|
124
125
|
if (typeof decorator === 'function') {
|
|
125
126
|
this.decorators[name] = decorator;
|
|
126
127
|
}
|
|
128
|
+
this.customValidators.push(name);
|
|
127
129
|
}
|
|
128
130
|
registerDecorator(name, decorator) {
|
|
129
131
|
this.decorators[name] = decorator;
|
|
@@ -138,7 +140,10 @@ export class FormValidation {
|
|
|
138
140
|
const isRequired = entry.rules.includes('required');
|
|
139
141
|
const value = data[entry.field[0]];
|
|
140
142
|
const possiblyValidDataExists = typeof value === 'string';
|
|
141
|
-
const
|
|
143
|
+
const usesCustomValidators = this.fieldRules[i].rules.some((rule) => {
|
|
144
|
+
return this.customValidators.includes(rule);
|
|
145
|
+
});
|
|
146
|
+
const isContent = !usesCustomValidators && !isRequired && (!possiblyValidDataExists || value.trim().length === 0);
|
|
142
147
|
if (!isContent) {
|
|
143
148
|
for (let j = 0; j < entry.rules.length; j++) {
|
|
144
149
|
const rule = entry.rules[j];
|
package/package.json
CHANGED
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"type": "module",
|
|
21
21
|
"main": "build/index",
|
|
22
|
-
"version": "1.0.
|
|
22
|
+
"version": "1.0.2",
|
|
23
23
|
"scripts": {
|
|
24
24
|
"develop": "tsc --watch",
|
|
25
25
|
"startDev": "cd build && nodemon --watch '../app/**/*' --watch '../build/**/*' -e js,html,css index.js",
|