dry-ux 1.53.0 → 1.54.0
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/dist/dajaxice/DajaxiceProxy.test.d.ts +1 -1
- package/dist/dajaxice/Proxy.interface.d.ts +47 -3
- package/dist/enhanced-inputs/HTMLInputs.d.ts +15 -0
- package/dist/enhanced-inputs/HTMLInputs.js +56 -0
- package/dist/enhanced-inputs/Validaition.d.ts +142 -0
- package/dist/enhanced-inputs/Validaition.js +368 -0
- package/dist/enhanced-inputs/interface.d.ts +109 -0
- package/dist/enhanced-inputs/interface.js +2 -0
- package/dist/enhanced-inputs/styles.css +13 -0
- package/dist/enhanced-inputs/withEnhancements.d.ts +86 -0
- package/dist/enhanced-inputs/withEnhancements.js +74 -0
- package/dist/error/ErrorBoundary.d.ts +45 -1
- package/dist/error/ErrorBoundary.js +26 -0
- package/dist/error/ErrorScreen.d.ts +5 -1
- package/dist/error/ErrorScreen.js +4 -0
- package/dist/helpers/flat.d.ts +14 -2
- package/dist/helpers/flat.js +2 -3
- package/dist/helpers/logger.d.ts +16 -0
- package/dist/helpers/utilities.d.ts +56 -4
- package/dist/helpers/utilities.js +69 -4
- package/dist/index.d.ts +3 -0
- package/dist/index.js +6 -1
- package/dist/ui-utils/Loader.d.ts +20 -0
- package/dist/ui-utils/Loader.js +20 -0
- package/dist/ui-utils/RenderWhenVisible.d.ts +7 -0
- package/dist/ui-utils/RenderWhenVisible.js +7 -0
- package/dist/ui-utils/Spinner.d.ts +6 -1
- package/dist/ui-utils/Spinner.js +5 -0
- package/dist/ui-utils/UIUtil.interface.d.ts +6 -7
- package/dist/ui-utils/UIUtilProvider.d.ts +1 -1
- package/dist/ui-utils/UIUtilRenderer.d.ts +1 -1
- package/package.json +4 -2
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Represents the arguments for a Dajaxice function.
|
|
3
|
+
* @template T The type of the arguments.
|
|
4
|
+
*/
|
|
5
|
+
export type Args<T = void> = {
|
|
6
|
+
/**
|
|
7
|
+
* The arguments for the Dajaxice function.
|
|
8
|
+
*/
|
|
2
9
|
args: T;
|
|
3
10
|
/**
|
|
4
11
|
* If true, it will show a loader when a Dajaxice function is called. Defaults to false.
|
|
@@ -27,16 +34,53 @@ export declare type Args<T = void> = {
|
|
|
27
34
|
loader?: boolean;
|
|
28
35
|
};
|
|
29
36
|
};
|
|
30
|
-
|
|
37
|
+
/**
|
|
38
|
+
* Represents the argument type for a Dajaxice function.
|
|
39
|
+
* @template T The type of the arguments.
|
|
40
|
+
*/
|
|
41
|
+
type ArgType<T> = T extends void ? Omit<Args, "args"> | void : Args<T>;
|
|
42
|
+
/**
|
|
43
|
+
* Represents a Dajaxice function.
|
|
44
|
+
* @template TArgs The type of the arguments.
|
|
45
|
+
* @template TResult The type of the result.
|
|
46
|
+
*/
|
|
31
47
|
export declare type DajaxiceFn<TArgs = void> = <TResult = any>(args: ArgType<TArgs>) => Promise<TResult>;
|
|
32
|
-
|
|
48
|
+
/**
|
|
49
|
+
* Represents the method arguments for a Dajaxice function.
|
|
50
|
+
*/
|
|
51
|
+
export type MethodArgs = Partial<Args<any>>;
|
|
52
|
+
/**
|
|
53
|
+
* Represents a Dajaxice proxy.
|
|
54
|
+
* @template TModule The type of the module.
|
|
55
|
+
*/
|
|
33
56
|
export interface IDajaxiceProxy<TModule> {
|
|
57
|
+
/**
|
|
58
|
+
* The modules of the Dajaxice proxy.
|
|
59
|
+
*/
|
|
34
60
|
modules: TModule;
|
|
61
|
+
/**
|
|
62
|
+
* The authentication check configuration.
|
|
63
|
+
*/
|
|
35
64
|
authCheck?: {
|
|
65
|
+
/**
|
|
66
|
+
* The URL to check for authentication.
|
|
67
|
+
*/
|
|
36
68
|
url: string;
|
|
69
|
+
/**
|
|
70
|
+
* The URL to redirect to if not authenticated.
|
|
71
|
+
*/
|
|
37
72
|
redirectUrl: string;
|
|
38
73
|
};
|
|
74
|
+
/**
|
|
75
|
+
* The error handler function.
|
|
76
|
+
* @param error The error object.
|
|
77
|
+
* @param method The method name.
|
|
78
|
+
* @param args The method arguments.
|
|
79
|
+
*/
|
|
39
80
|
onError?: (error: any, method: string, args: any) => void;
|
|
81
|
+
/**
|
|
82
|
+
* If true, it will show a loader when a Dajaxice function is called. Defaults to false.
|
|
83
|
+
*/
|
|
40
84
|
loader?: boolean;
|
|
41
85
|
}
|
|
42
86
|
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { IEnhancedProps } from "./interface";
|
|
3
|
+
import "./styles.css";
|
|
4
|
+
/**
|
|
5
|
+
* Forwarded ref input component with enhancements.
|
|
6
|
+
*/
|
|
7
|
+
export declare const Input: React.ForwardRefExoticComponent<React.InputHTMLAttributes<HTMLInputElement> & IEnhancedProps & React.RefAttributes<HTMLInputElement>>;
|
|
8
|
+
/**
|
|
9
|
+
* Forwarded ref select component with enhancements.
|
|
10
|
+
*/
|
|
11
|
+
export declare const Select: React.ForwardRefExoticComponent<React.InputHTMLAttributes<HTMLSelectElement> & IEnhancedProps & React.RefAttributes<HTMLInputElement>>;
|
|
12
|
+
/**
|
|
13
|
+
* Forwarded ref textarea component with enhancements.
|
|
14
|
+
*/
|
|
15
|
+
export declare const TextArea: React.ForwardRefExoticComponent<React.InputHTMLAttributes<HTMLTextAreaElement> & IEnhancedProps & React.RefAttributes<HTMLInputElement>>;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
+
var t = {};
|
|
4
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
+
t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
+
t[p[i]] = s[p[i]];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.TextArea = exports.Select = exports.Input = void 0;
|
|
15
|
+
const React = require("react");
|
|
16
|
+
const withEnhancements_1 = require("./withEnhancements");
|
|
17
|
+
require("./styles.css");
|
|
18
|
+
/**
|
|
19
|
+
* Enhanced input component with enhancements applied.
|
|
20
|
+
*/
|
|
21
|
+
const EnhancedInput = (0, withEnhancements_1.withEnhancements)((_a) => {
|
|
22
|
+
var { inputRef } = _a, props = __rest(_a, ["inputRef"]);
|
|
23
|
+
return (React.createElement("input", Object.assign({ ref: inputRef }, props)));
|
|
24
|
+
});
|
|
25
|
+
/**
|
|
26
|
+
* Forwarded ref input component with enhancements.
|
|
27
|
+
*/
|
|
28
|
+
exports.Input = React.forwardRef((props, ref) => {
|
|
29
|
+
return React.createElement(EnhancedInput, Object.assign({}, props, { inputRef: ref }));
|
|
30
|
+
});
|
|
31
|
+
/**
|
|
32
|
+
* Enhanced select component with enhancements applied.
|
|
33
|
+
*/
|
|
34
|
+
const EnhancedSelect = (0, withEnhancements_1.withEnhancements)((_a) => {
|
|
35
|
+
var { inputRef } = _a, props = __rest(_a, ["inputRef"]);
|
|
36
|
+
return (React.createElement("select", Object.assign({ ref: inputRef }, props)));
|
|
37
|
+
});
|
|
38
|
+
/**
|
|
39
|
+
* Forwarded ref select component with enhancements.
|
|
40
|
+
*/
|
|
41
|
+
exports.Select = React.forwardRef((props, ref) => {
|
|
42
|
+
return React.createElement(EnhancedSelect, Object.assign({}, props, { inputRef: ref }));
|
|
43
|
+
});
|
|
44
|
+
/**
|
|
45
|
+
* Enhanced textarea component with enhancements applied.
|
|
46
|
+
*/
|
|
47
|
+
const EnhancedTextArea = (0, withEnhancements_1.withEnhancements)((_a) => {
|
|
48
|
+
var { inputRef } = _a, props = __rest(_a, ["inputRef"]);
|
|
49
|
+
return (React.createElement("textarea", Object.assign({ ref: inputRef }, props)));
|
|
50
|
+
});
|
|
51
|
+
/**
|
|
52
|
+
* Forwarded ref textarea component with enhancements.
|
|
53
|
+
*/
|
|
54
|
+
exports.TextArea = React.forwardRef((props, ref) => {
|
|
55
|
+
return React.createElement(EnhancedTextArea, Object.assign({}, props, { inputRef: ref }));
|
|
56
|
+
});
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
type InputElement = HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement;
|
|
2
|
+
/**
|
|
3
|
+
* Class representing a generic DOM element with utility methods for manipulation and validation.
|
|
4
|
+
*/
|
|
5
|
+
export declare class Element {
|
|
6
|
+
native: HTMLElement;
|
|
7
|
+
/**
|
|
8
|
+
* Creates an instance of Element.
|
|
9
|
+
* @param native The native HTML element.
|
|
10
|
+
*/
|
|
11
|
+
constructor(native: HTMLElement);
|
|
12
|
+
/**
|
|
13
|
+
* Gets the value of the input element.
|
|
14
|
+
* @returns The value of the input element.
|
|
15
|
+
*/
|
|
16
|
+
val(): string;
|
|
17
|
+
/**
|
|
18
|
+
* Checks if the element has a specific class.
|
|
19
|
+
* @param className The class name to check.
|
|
20
|
+
* @returns True if the element has the class, false otherwise.
|
|
21
|
+
*/
|
|
22
|
+
hasClass(className: string): boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Removes a specific class from the element.
|
|
25
|
+
* @param className The class name to remove.
|
|
26
|
+
*/
|
|
27
|
+
removeClass(className: string): void;
|
|
28
|
+
/**
|
|
29
|
+
* Gets the value of a data attribute.
|
|
30
|
+
* @param attribute The data attribute name.
|
|
31
|
+
* @returns The value of the data attribute.
|
|
32
|
+
*/
|
|
33
|
+
data(attribute: string): string;
|
|
34
|
+
/**
|
|
35
|
+
* Checks if the element is visible.
|
|
36
|
+
* @returns True if the element is visible, false otherwise.
|
|
37
|
+
*/
|
|
38
|
+
visible(): boolean;
|
|
39
|
+
/**
|
|
40
|
+
* Gets the closest ancestor element that matches the selector.
|
|
41
|
+
* @param selector The selector to match.
|
|
42
|
+
* @returns The closest ancestor element.
|
|
43
|
+
*/
|
|
44
|
+
parents(selector: string): Element;
|
|
45
|
+
/**
|
|
46
|
+
* Gets the next sibling element.
|
|
47
|
+
* @returns The next sibling element.
|
|
48
|
+
*/
|
|
49
|
+
next(): Element | null;
|
|
50
|
+
/**
|
|
51
|
+
* Inserts HTML after the element.
|
|
52
|
+
* @param html The HTML to insert.
|
|
53
|
+
*/
|
|
54
|
+
after(html: string): void;
|
|
55
|
+
/**
|
|
56
|
+
* Adds a class to the element.
|
|
57
|
+
* @param className The class name to add.
|
|
58
|
+
*/
|
|
59
|
+
addClass(className: string): void;
|
|
60
|
+
/**
|
|
61
|
+
* Removes the element from the DOM.
|
|
62
|
+
*/
|
|
63
|
+
remove(): void;
|
|
64
|
+
/**
|
|
65
|
+
* Gets the native input element.
|
|
66
|
+
* @returns The native input element.
|
|
67
|
+
*/
|
|
68
|
+
get nativeInput(): InputElement;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Options for configuring the validation.
|
|
72
|
+
*/
|
|
73
|
+
type ValidationOptions = {
|
|
74
|
+
/**
|
|
75
|
+
* The form element and its configuration.
|
|
76
|
+
*/
|
|
77
|
+
form?: {
|
|
78
|
+
/**
|
|
79
|
+
* The ID of the form element.
|
|
80
|
+
*/
|
|
81
|
+
id?: string;
|
|
82
|
+
/**
|
|
83
|
+
* The form element itself.
|
|
84
|
+
*/
|
|
85
|
+
element?: HTMLFormElement;
|
|
86
|
+
/**
|
|
87
|
+
* Whether to bind validation to value changes.
|
|
88
|
+
*/
|
|
89
|
+
bindToValueChanges?: boolean;
|
|
90
|
+
};
|
|
91
|
+
/**
|
|
92
|
+
* Whether to use modern error messages.
|
|
93
|
+
*/
|
|
94
|
+
modernErrorMessage?: boolean;
|
|
95
|
+
};
|
|
96
|
+
/**
|
|
97
|
+
* Class representing form validation.
|
|
98
|
+
*/
|
|
99
|
+
export declare class Validation {
|
|
100
|
+
private readonly form;
|
|
101
|
+
private readonly modernErrorMessage;
|
|
102
|
+
/**
|
|
103
|
+
* Creates an instance of Validation.
|
|
104
|
+
* @param options The options for configuring the validation.
|
|
105
|
+
*/
|
|
106
|
+
constructor(options?: ValidationOptions);
|
|
107
|
+
/**
|
|
108
|
+
* Binds the form to value changes for validation.
|
|
109
|
+
* @param input The input element or its ID.
|
|
110
|
+
*/
|
|
111
|
+
bindToValueChanges(input: HTMLElement | string): void;
|
|
112
|
+
/**
|
|
113
|
+
* Validates the entire form.
|
|
114
|
+
* @returns True if the form is valid, false otherwise.
|
|
115
|
+
*/
|
|
116
|
+
validateForm(): boolean;
|
|
117
|
+
/**
|
|
118
|
+
* Validates a specific input element.
|
|
119
|
+
* @param input The input element or its ID.
|
|
120
|
+
* @returns True if the input is valid, false otherwise.
|
|
121
|
+
*/
|
|
122
|
+
validateInput(input: HTMLElement | string): boolean;
|
|
123
|
+
/**
|
|
124
|
+
* Validates a specific element.
|
|
125
|
+
* @param element The element to validate.
|
|
126
|
+
* @returns True if the element is valid, false otherwise.
|
|
127
|
+
*/
|
|
128
|
+
private validate;
|
|
129
|
+
/**
|
|
130
|
+
* Gets the elements to be validated.
|
|
131
|
+
* @param form The form element.
|
|
132
|
+
* @returns An array of elements to be validated.
|
|
133
|
+
*/
|
|
134
|
+
private getElements;
|
|
135
|
+
/**
|
|
136
|
+
* Validates a date string.
|
|
137
|
+
* @param value The date string to validate.
|
|
138
|
+
* @returns True if the date is valid, false otherwise.
|
|
139
|
+
*/
|
|
140
|
+
private validateDate;
|
|
141
|
+
}
|
|
142
|
+
export {};
|
|
@@ -0,0 +1,368 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Validation = exports.Element = void 0;
|
|
4
|
+
const daysOfWeek = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
|
|
5
|
+
/**
|
|
6
|
+
* Class representing a generic DOM element with utility methods for manipulation and validation.
|
|
7
|
+
*/
|
|
8
|
+
class Element {
|
|
9
|
+
/**
|
|
10
|
+
* Creates an instance of Element.
|
|
11
|
+
* @param native The native HTML element.
|
|
12
|
+
*/
|
|
13
|
+
constructor(native) {
|
|
14
|
+
this.native = native;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Gets the value of the input element.
|
|
18
|
+
* @returns The value of the input element.
|
|
19
|
+
*/
|
|
20
|
+
val() {
|
|
21
|
+
return this.nativeInput.value;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Checks if the element has a specific class.
|
|
25
|
+
* @param className The class name to check.
|
|
26
|
+
* @returns True if the element has the class, false otherwise.
|
|
27
|
+
*/
|
|
28
|
+
hasClass(className) {
|
|
29
|
+
return this.native.classList.contains(className);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Removes a specific class from the element.
|
|
33
|
+
* @param className The class name to remove.
|
|
34
|
+
*/
|
|
35
|
+
removeClass(className) {
|
|
36
|
+
this.native.classList.remove(className);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Gets the value of a data attribute.
|
|
40
|
+
* @param attribute The data attribute name.
|
|
41
|
+
* @returns The value of the data attribute.
|
|
42
|
+
*/
|
|
43
|
+
data(attribute) {
|
|
44
|
+
return this.native.getAttribute(attribute);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Checks if the element is visible.
|
|
48
|
+
* @returns True if the element is visible, false otherwise.
|
|
49
|
+
*/
|
|
50
|
+
visible() {
|
|
51
|
+
return !!(this.native.offsetWidth || this.native.offsetHeight || this.native.getClientRects().length);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Gets the closest ancestor element that matches the selector.
|
|
55
|
+
* @param selector The selector to match.
|
|
56
|
+
* @returns The closest ancestor element.
|
|
57
|
+
*/
|
|
58
|
+
parents(selector) {
|
|
59
|
+
return new Element(this.native.closest(selector));
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Gets the next sibling element.
|
|
63
|
+
* @returns The next sibling element.
|
|
64
|
+
*/
|
|
65
|
+
next() {
|
|
66
|
+
return !!this.native.nextElementSibling ? new Element(this.native.nextElementSibling) : null;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Inserts HTML after the element.
|
|
70
|
+
* @param html The HTML to insert.
|
|
71
|
+
*/
|
|
72
|
+
after(html) {
|
|
73
|
+
this.native.insertAdjacentHTML("afterend", html);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Adds a class to the element.
|
|
77
|
+
* @param className The class name to add.
|
|
78
|
+
*/
|
|
79
|
+
addClass(className) {
|
|
80
|
+
this.native.classList.add(className);
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Removes the element from the DOM.
|
|
84
|
+
*/
|
|
85
|
+
remove() {
|
|
86
|
+
this.native.remove();
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Gets the native input element.
|
|
90
|
+
* @returns The native input element.
|
|
91
|
+
*/
|
|
92
|
+
get nativeInput() {
|
|
93
|
+
return this.native;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
exports.Element = Element;
|
|
97
|
+
/**
|
|
98
|
+
* Class representing form validation.
|
|
99
|
+
*/
|
|
100
|
+
class Validation {
|
|
101
|
+
/**
|
|
102
|
+
* Creates an instance of Validation.
|
|
103
|
+
* @param options The options for configuring the validation.
|
|
104
|
+
*/
|
|
105
|
+
constructor(options) {
|
|
106
|
+
/**
|
|
107
|
+
* Gets the elements to be validated.
|
|
108
|
+
* @param form The form element.
|
|
109
|
+
* @returns An array of elements to be validated.
|
|
110
|
+
*/
|
|
111
|
+
this.getElements = (form) => Array.from(form.getElementsByClassName("validate")).map(field => new Element(field));
|
|
112
|
+
const { form, modernErrorMessage } = options || {};
|
|
113
|
+
if ((form === null || form === void 0 ? void 0 : form.id) || (form === null || form === void 0 ? void 0 : form.element)) {
|
|
114
|
+
this.form = typeof form.id ? document.getElementById(form.id) : form.element;
|
|
115
|
+
if (form.bindToValueChanges) {
|
|
116
|
+
this.getElements(this.form).forEach(element => this.bindToValueChanges(element.native));
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
this.modernErrorMessage = modernErrorMessage;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Binds the form to value changes for validation.
|
|
123
|
+
* @param input The input element or its ID.
|
|
124
|
+
*/
|
|
125
|
+
bindToValueChanges(input) {
|
|
126
|
+
const element = typeof input === "string" ? new Element(document.getElementById(input)) : new Element(input);
|
|
127
|
+
element.native.addEventListener("change", event => this.validate(element));
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Validates the entire form.
|
|
131
|
+
* @returns True if the form is valid, false otherwise.
|
|
132
|
+
*/
|
|
133
|
+
validateForm() {
|
|
134
|
+
return this.getElements(this.form).filter(element => !this.validate(element)).length === 0;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Validates a specific input element.
|
|
138
|
+
* @param input The input element or its ID.
|
|
139
|
+
* @returns True if the input is valid, false otherwise.
|
|
140
|
+
*/
|
|
141
|
+
validateInput(input) {
|
|
142
|
+
const element = typeof input === "string" ? new Element(document.getElementById(input)) : new Element(input);
|
|
143
|
+
return this.validate(element);
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Validates a specific element.
|
|
147
|
+
* @param element The element to validate.
|
|
148
|
+
* @returns True if the element is valid, false otherwise.
|
|
149
|
+
*/
|
|
150
|
+
validate(element) {
|
|
151
|
+
var _a;
|
|
152
|
+
if (!element.visible() && !element.hasClass("validate-hidden")) {
|
|
153
|
+
return true;
|
|
154
|
+
}
|
|
155
|
+
let val = element.val(), errorRefAttr = element.data("validationErrorRef");
|
|
156
|
+
let isValid = true;
|
|
157
|
+
let errorMsg = "";
|
|
158
|
+
const numericValue = Number(val);
|
|
159
|
+
if (element.data("validationTrim") != null) {
|
|
160
|
+
const trim = element.data("validationTrim");
|
|
161
|
+
for (let i = 0, len = trim.length; i < len; i++) {
|
|
162
|
+
val = val.split(trim[i]).join("");
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
//Optional: data-required-message
|
|
166
|
+
if (element.hasClass("validate-required") && isValid) {
|
|
167
|
+
isValid = val != "";
|
|
168
|
+
if (element.data("requiredMessage") != null)
|
|
169
|
+
errorMsg = element.data("requiredMessage");
|
|
170
|
+
else
|
|
171
|
+
errorMsg = "This field is required";
|
|
172
|
+
}
|
|
173
|
+
//Optional: data-number-message
|
|
174
|
+
if (element.hasClass("validate-number") && isValid) {
|
|
175
|
+
isValid = !isNaN(numericValue);
|
|
176
|
+
if (element.data("numberMessage") != null)
|
|
177
|
+
errorMsg = element.data("numberMessage");
|
|
178
|
+
else
|
|
179
|
+
errorMsg = "Please enter a valid number";
|
|
180
|
+
}
|
|
181
|
+
//Optional: data-money-message
|
|
182
|
+
if (element.hasClass("validate-money") && isValid) {
|
|
183
|
+
isValid = !isNaN(numericValue);
|
|
184
|
+
if (isValid)
|
|
185
|
+
isValid = numericValue >= 0;
|
|
186
|
+
if (element.data("moneyMessage") != null)
|
|
187
|
+
errorMsg = element.data("moneyMessage");
|
|
188
|
+
else
|
|
189
|
+
errorMsg = "Please enter a valid amount";
|
|
190
|
+
}
|
|
191
|
+
//Optional: data-positive-number-message
|
|
192
|
+
if (element.hasClass("validate-positive-number") && isValid) {
|
|
193
|
+
isValid = !isNaN(numericValue);
|
|
194
|
+
if (isValid)
|
|
195
|
+
isValid = numericValue >= 0;
|
|
196
|
+
if (element.data("positiveNumberMessage") != null)
|
|
197
|
+
errorMsg = element.data("positiveNumberMessage");
|
|
198
|
+
else
|
|
199
|
+
errorMsg = "Please enter a valid positive number";
|
|
200
|
+
}
|
|
201
|
+
//Optional: data-email-message
|
|
202
|
+
if (element.hasClass("validate-email") && isValid) {
|
|
203
|
+
var emailRegEx = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;
|
|
204
|
+
isValid = val.search(emailRegEx) != -1;
|
|
205
|
+
if (element.data("emailMessage") != null)
|
|
206
|
+
errorMsg = element.data("emailMessage");
|
|
207
|
+
else
|
|
208
|
+
errorMsg = "Please enter Email in correct format";
|
|
209
|
+
}
|
|
210
|
+
//Optional: data-digits-message
|
|
211
|
+
if (element.hasClass("validate-digits") && isValid) {
|
|
212
|
+
isValid = val.match(/[0-9]*/)[0].length == val.length;
|
|
213
|
+
if (element.data("digitsMessage") != null)
|
|
214
|
+
errorMsg = element.data("digitsMessage");
|
|
215
|
+
else
|
|
216
|
+
errorMsg = "Only digits allowed";
|
|
217
|
+
}
|
|
218
|
+
//Required: data-compare attribute to the field and specify the ID of the input to compare with
|
|
219
|
+
//Optional: data-compare-message
|
|
220
|
+
if (element.hasClass("validate-compare") && isValid) {
|
|
221
|
+
if (element.data("compare") != null) {
|
|
222
|
+
const compareTo = new Element(document.getElementById(element.data("compare"))).val();
|
|
223
|
+
isValid = compareTo == val;
|
|
224
|
+
if (element.data("compareMessage") != null)
|
|
225
|
+
errorMsg = element.data("compareMessage");
|
|
226
|
+
else
|
|
227
|
+
errorMsg = "Values do not match";
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
//Required: data-min-length to the field and specify the minimum length required
|
|
231
|
+
//Optional: data-min-length-message
|
|
232
|
+
if (element.hasClass("validate-min-length") && isValid) {
|
|
233
|
+
if (element.data("minLength") != null) {
|
|
234
|
+
const maxLength = parseInt(element.data("minLength"));
|
|
235
|
+
isValid = val.length >= maxLength;
|
|
236
|
+
if (element.data("minLengthMessage") != null)
|
|
237
|
+
errorMsg = element.data("minLengthMessage");
|
|
238
|
+
else
|
|
239
|
+
errorMsg = "Minimum " + maxLength + " characters required.";
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
//Required: data-min-digits-length to the field and specify the minimum length required
|
|
243
|
+
//Optional: data-min-digits-length-message
|
|
244
|
+
if (element.hasClass("validate-min-digits-length") && isValid) {
|
|
245
|
+
if (element.data("minDigitsLength") != null) {
|
|
246
|
+
const minLength = parseInt(element.data("minDigitsLength"));
|
|
247
|
+
isValid = val.replace(/[^0-9]/g, "").length >= minLength;
|
|
248
|
+
if (element.data("minDigitsLengthMessage") != null)
|
|
249
|
+
errorMsg = element.data("minDigitsLengthMessage");
|
|
250
|
+
else
|
|
251
|
+
errorMsg = "Minimum " + minLength + " digits required.";
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
//Required: data-max-length to the field and specify the maximum length allowed
|
|
255
|
+
//Optional: data-maxlength-message
|
|
256
|
+
if (element.hasClass("validate-max-length") && isValid) {
|
|
257
|
+
if (element.data("maxLength") != null) {
|
|
258
|
+
const maxlength = parseInt(element.data("maxLength"));
|
|
259
|
+
isValid = val.length <= maxlength;
|
|
260
|
+
if (element.data("maxLengthMessage") != null)
|
|
261
|
+
errorMsg = element.data("maxLengthMessage");
|
|
262
|
+
else
|
|
263
|
+
errorMsg = "Maximum " + maxlength + " characters allowed.";
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
//Optional: data-date-message
|
|
267
|
+
if (element.hasClass("validate-date") && isValid) {
|
|
268
|
+
isValid = this.validateDate(val);
|
|
269
|
+
if (element.data("dateMessage") != null)
|
|
270
|
+
errorMsg = element.data("dateMessage");
|
|
271
|
+
else
|
|
272
|
+
errorMsg = "Not a valid date";
|
|
273
|
+
}
|
|
274
|
+
//Required: data-max-value to the field and specify the maximum value allowed
|
|
275
|
+
//Optional: data-maxvalue-message
|
|
276
|
+
if (element.hasClass("validate-max-value") && isValid) {
|
|
277
|
+
if (element.data("maxValue") != null) {
|
|
278
|
+
const maxvalue = parseFloat(element.data("maxValue"));
|
|
279
|
+
if (val.length > 0 && !isNaN(numericValue))
|
|
280
|
+
isValid = parseFloat(val) <= maxvalue;
|
|
281
|
+
if (element.data("maxvalueMessage") != null)
|
|
282
|
+
errorMsg = element.data("maxvalueMessage");
|
|
283
|
+
else
|
|
284
|
+
errorMsg = "Value cannot be more than " + maxvalue + ".";
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
//Required: data-max-date to the field and specify the maximum date allowed
|
|
288
|
+
//Optional: data-max-date-message
|
|
289
|
+
if (element.hasClass("validate-max-date") && isValid) {
|
|
290
|
+
if (element.data("maxDate") != null) {
|
|
291
|
+
const maxDate = new Date(element.data("maxDate"));
|
|
292
|
+
const day = new Date(val);
|
|
293
|
+
isValid = day <= maxDate;
|
|
294
|
+
if (element.data("maxDateMessage") != null)
|
|
295
|
+
errorMsg = element.data("maxDateMessage");
|
|
296
|
+
else
|
|
297
|
+
errorMsg = "Date cannot be more than " + maxDate + ".";
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
//Required: data-min-date to the field and specify the maximum date allowed
|
|
301
|
+
//Optional: data-min-date-message
|
|
302
|
+
if (element.hasClass("validate-min-date") && isValid) {
|
|
303
|
+
if (element.data("minDate") != null) {
|
|
304
|
+
const minDate = new Date(element.data("minDate"));
|
|
305
|
+
const day = new Date(val);
|
|
306
|
+
isValid = day >= minDate;
|
|
307
|
+
if (element.data("minDateMessage") != null)
|
|
308
|
+
errorMsg = element.data("minDateMessage");
|
|
309
|
+
else
|
|
310
|
+
errorMsg = "Date cannot be less than " + minDate + ".";
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
if (element.hasClass("validate-disallowed-days-of-week") && isValid) {
|
|
314
|
+
const disallowedDays = element.data("disallowedDaysOfWeek").toString().split(",");
|
|
315
|
+
try {
|
|
316
|
+
const day = new Date(val).getUTCDay().toString();
|
|
317
|
+
// Days in JS range from 0-6 where 0 is Sunday and 6 is Saturday
|
|
318
|
+
isValid = !disallowedDays.some(d => d == day);
|
|
319
|
+
if (!isValid) {
|
|
320
|
+
errorMsg = `${daysOfWeek[parseInt(day)]} not allowed! Please pick a different day.`;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
catch (e) { }
|
|
324
|
+
}
|
|
325
|
+
const errorRef = errorRefAttr ? element.parents(errorRefAttr) : element;
|
|
326
|
+
if ((_a = errorRef.next()) === null || _a === void 0 ? void 0 : _a.hasClass("error-message")) {
|
|
327
|
+
errorRef.next().remove();
|
|
328
|
+
}
|
|
329
|
+
//Checking if control is valid and performing necessary action
|
|
330
|
+
if (isValid) {
|
|
331
|
+
errorRef.removeClass("error-background");
|
|
332
|
+
return true;
|
|
333
|
+
}
|
|
334
|
+
else {
|
|
335
|
+
if (errorMsg !== "") {
|
|
336
|
+
if (this.modernErrorMessage) {
|
|
337
|
+
element.nativeInput.setCustomValidity(errorMsg);
|
|
338
|
+
element.nativeInput.reportValidity();
|
|
339
|
+
}
|
|
340
|
+
else {
|
|
341
|
+
errorRef.after("<div class='error-message'>" + errorMsg + "</div>");
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
if (!element.hasClass("validation-no-error-background")) {
|
|
345
|
+
errorRef.addClass("error-background");
|
|
346
|
+
}
|
|
347
|
+
return false;
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
/**
|
|
351
|
+
* Validates a date string.
|
|
352
|
+
* @param value The date string to validate.
|
|
353
|
+
* @returns True if the date is valid, false otherwise.
|
|
354
|
+
*/
|
|
355
|
+
validateDate(value) {
|
|
356
|
+
const format = /^\d{2}\/\d{2}\/\d{4}$/; //Basic check for format validity
|
|
357
|
+
if (!format.test(value)) {
|
|
358
|
+
return false;
|
|
359
|
+
}
|
|
360
|
+
else {
|
|
361
|
+
//Detailed check for valid date ranges
|
|
362
|
+
const [month, day, year] = value.split("/").map(Number);
|
|
363
|
+
const date = new Date(year, month - 1, day);
|
|
364
|
+
return !(date.getMonth() + 1 != month || date.getDate() != day || date.getFullYear() != year);
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
exports.Validation = Validation;
|