inviton-powerduck 0.0.157 → 0.0.159
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/common/validation.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Validation } from '@vuelidate/core';
|
|
2
2
|
import type { PowerduckViewModelBase } from './base-component';
|
|
3
3
|
import type { IValidationSet, ValidationRuleset, ValidationState } from './static-wrappers/interfaces/validation-interface';
|
|
4
|
+
import { Temporal } from '@js-temporal/polyfill';
|
|
4
5
|
import {
|
|
5
6
|
alpha,
|
|
6
7
|
alphaNum,
|
|
@@ -21,10 +22,11 @@ import {
|
|
|
21
22
|
requiredUnless,
|
|
22
23
|
url,
|
|
23
24
|
} from '@vuelidate/validators';
|
|
25
|
+
import { unref } from 'vue';
|
|
24
26
|
import PowerduckState from '../app/powerduck-state';
|
|
27
|
+
import { capitalize } from './extensions/string-extensions';
|
|
25
28
|
import LocalizedValueHelper from './localized-value-helper';
|
|
26
29
|
import { isNullOrEmpty } from './utils/is-null-or-empty';
|
|
27
|
-
import { capitalize } from './extensions/string-extensions';
|
|
28
30
|
|
|
29
31
|
const getFirstUnsattisfiedValidatorName = (valProp: Validation): string | null => {
|
|
30
32
|
const errors = valProp?.$errors || [];
|
|
@@ -134,6 +136,43 @@ export class ValidationHelper {
|
|
|
134
136
|
}
|
|
135
137
|
}
|
|
136
138
|
|
|
139
|
+
const customReq = (value: any): boolean => {
|
|
140
|
+
value = unref(value);
|
|
141
|
+
|
|
142
|
+
if (Array.isArray(value)) {
|
|
143
|
+
return !!value.length;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
if (value === undefined || value === null) {
|
|
147
|
+
return false;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
if (value === false) {
|
|
151
|
+
return true;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
if (value instanceof Date) {
|
|
155
|
+
return !isNaN(value.getTime());
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
if (typeof Temporal !== 'undefined') {
|
|
159
|
+
if (value instanceof Temporal.PlainDateTime || value instanceof Temporal.PlainDate || value instanceof Temporal.ZonedDateTime || value instanceof Temporal.Instant) {
|
|
160
|
+
return true;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
if (typeof value === 'object') {
|
|
165
|
+
// eslint-disable-next-line no-unreachable-loop
|
|
166
|
+
for (const _ in value) {
|
|
167
|
+
return true;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
return false;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
return !!String(value).length;
|
|
174
|
+
};
|
|
175
|
+
|
|
137
176
|
export class ValidationBuilder {
|
|
138
177
|
private _validationArgs: any = {};
|
|
139
178
|
|
|
@@ -150,8 +189,30 @@ export class ValidationBuilder {
|
|
|
150
189
|
return this;
|
|
151
190
|
}
|
|
152
191
|
|
|
153
|
-
requiredIf
|
|
154
|
-
|
|
192
|
+
requiredIf(field: string | ((vm: any, parentVm?: PowerduckViewModelBase) => boolean)): ValidationBuilder {
|
|
193
|
+
const requireIf = (propOrFunction: boolean | string | ((...args: any[]) => boolean)) => {
|
|
194
|
+
const validate = (prop: any, val: any) => prop ? customReq(typeof val === 'string' ? val.trim() : val) : true;
|
|
195
|
+
|
|
196
|
+
return function (
|
|
197
|
+
this: any,
|
|
198
|
+
value: any,
|
|
199
|
+
parentVM: any,
|
|
200
|
+
) {
|
|
201
|
+
if (typeof propOrFunction != 'function') {
|
|
202
|
+
return validate((propOrFunction), value);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
const result = propOrFunction.call(
|
|
206
|
+
this,
|
|
207
|
+
value,
|
|
208
|
+
parentVM,
|
|
209
|
+
);
|
|
210
|
+
return validate(result, value);
|
|
211
|
+
};
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
this._validationArgs.requiredIf = requireIf(field);
|
|
215
|
+
|
|
155
216
|
return this;
|
|
156
217
|
}
|
|
157
218
|
|
|
@@ -29,7 +29,7 @@ function getFlaggedResult(h, state, originator): void {
|
|
|
29
29
|
if (originator == 'mobile') {
|
|
30
30
|
return (<span>{state.text}</span>);
|
|
31
31
|
} else {
|
|
32
|
-
return (<span><span class={`fi fi-${state.
|
|
32
|
+
return (<span><span class={`fi fi-${state.twoLetters}`}></span> {state.text}</span>);
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
|
|
@@ -1061,6 +1061,7 @@ import { utcEpochMilliseconds } from '../../../../common/extensions/temporal-ext
|
|
|
1061
1061
|
redrawDatePicker();
|
|
1062
1062
|
checkAndSetDefaultValue();
|
|
1063
1063
|
updateCalendarWidth();
|
|
1064
|
+
|
|
1064
1065
|
if (opt.customOpenAnimation) {
|
|
1065
1066
|
opt.customOpenAnimation.call(box.get(0), () => {
|
|
1066
1067
|
$(self).trigger('datepicker-opened', {
|
|
@@ -1955,22 +1956,18 @@ import { utcEpochMilliseconds } from '../../../../common/extensions/temporal-ext
|
|
|
1955
1956
|
showMonth(opt.month2, 'month2');
|
|
1956
1957
|
}
|
|
1957
1958
|
|
|
1958
|
-
function compare_month(
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
if (
|
|
1963
|
-
|
|
1964
|
-
|
|
1959
|
+
function compare_month(a: Temporal.PlainDateTime, b: Temporal.PlainDateTime): number {
|
|
1960
|
+
if (a.year !== b.year) {
|
|
1961
|
+
return a.year < b.year ? -1 : 1;
|
|
1962
|
+
}
|
|
1963
|
+
if (a.month !== b.month) {
|
|
1964
|
+
return a.month < b.month ? -1 : 1;
|
|
1965
|
+
}
|
|
1966
|
+
return 0;
|
|
1965
1967
|
}
|
|
1966
1968
|
|
|
1967
1969
|
function compare_day(m1: Temporal.PlainDateTime, m2: Temporal.PlainDateTime): number {
|
|
1968
|
-
|
|
1969
|
-
if (p > 0) { return 1; }
|
|
1970
|
-
|
|
1971
|
-
if (p === 0) { return 0; }
|
|
1972
|
-
|
|
1973
|
-
return -1;
|
|
1970
|
+
return Temporal.PlainDate.compare(m1.toPlainDate(), m2.toPlainDate());
|
|
1974
1971
|
}
|
|
1975
1972
|
|
|
1976
1973
|
function nextMonth(month: Temporal.PlainDateTime): Temporal.PlainDateTime {
|
|
@@ -2328,6 +2325,7 @@ import { utcEpochMilliseconds } from '../../../../common/extensions/temporal-ext
|
|
|
2328
2325
|
valid,
|
|
2329
2326
|
});
|
|
2330
2327
|
}
|
|
2328
|
+
|
|
2331
2329
|
const html = [];
|
|
2332
2330
|
for (let week = 0; week < 6; week++) {
|
|
2333
2331
|
if (days[week * 7].type == 'nextMonth') {
|
|
@@ -2339,7 +2337,7 @@ import { utcEpochMilliseconds } from '../../../../common/extensions/temporal-ext
|
|
|
2339
2337
|
for (var day: any = 0; day < 7; day++) {
|
|
2340
2338
|
const _day: any = (opt.startOfWeek == 'monday') ? day + 1 : day;
|
|
2341
2339
|
const today = days[week * 7 + _day];
|
|
2342
|
-
const highlightToday =
|
|
2340
|
+
const highlightToday = (Temporal.PlainDateTime.compare(today.date.toPlainDate(), now.toPlainDate()) == 0);
|
|
2343
2341
|
today.extraClass = '';
|
|
2344
2342
|
today.tooltip = '';
|
|
2345
2343
|
|