myrta-ui 17.0.0-beta.19 → 17.0.0-beta.20
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/esm2022/lib/services/index.mjs +2 -1
- package/esm2022/lib/services/mrx-form-validator/constants/invalid-messages.mjs +10 -0
- package/esm2022/lib/services/mrx-form-validator/helpers/get-error-message.helper.mjs +10 -0
- package/esm2022/lib/services/mrx-form-validator/helpers/get-sorting-validations.helper.mjs +29 -0
- package/esm2022/lib/services/mrx-form-validator/models/index.mjs +4 -0
- package/esm2022/lib/services/mrx-form-validator/models/validations-options.model.mjs +2 -0
- package/esm2022/lib/services/mrx-form-validator/models/validations-settings.model.mjs +2 -0
- package/esm2022/lib/services/mrx-form-validator/models/validations-types.model.mjs +22 -0
- package/esm2022/lib/services/mrx-form-validator/mrx-form-validator.mjs +97 -183
- package/esm2022/lib/services/mrx-form-validator/validations/callback.validation.mjs +15 -0
- package/esm2022/lib/services/mrx-form-validator/validations/email.validation.mjs +11 -0
- package/esm2022/lib/services/mrx-form-validator/validations/max-length.validation.mjs +14 -0
- package/esm2022/lib/services/mrx-form-validator/validations/max-value.validation.mjs +10 -0
- package/esm2022/lib/services/mrx-form-validator/validations/min-length.validation.mjs +15 -0
- package/esm2022/lib/services/mrx-form-validator/validations/min-value.validation.mjs +10 -0
- package/esm2022/lib/services/mrx-form-validator/validations/pattern.validation.mjs +11 -0
- package/esm2022/lib/services/mrx-form-validator/validations/required.validation.mjs +22 -0
- package/fesm2022/myrta-ui.mjs +254 -183
- package/fesm2022/myrta-ui.mjs.map +1 -1
- package/lib/services/index.d.ts +1 -0
- package/lib/services/mrx-form-validator/constants/invalid-messages.d.ts +9 -0
- package/lib/services/mrx-form-validator/helpers/get-error-message.helper.d.ts +3 -0
- package/lib/services/mrx-form-validator/helpers/get-sorting-validations.helper.d.ts +2 -0
- package/lib/services/mrx-form-validator/models/index.d.ts +3 -0
- package/lib/services/mrx-form-validator/models/validations-options.model.d.ts +31 -0
- package/lib/services/mrx-form-validator/models/validations-settings.model.d.ts +7 -0
- package/lib/services/mrx-form-validator/models/validations-types.model.d.ts +19 -0
- package/lib/services/mrx-form-validator/mrx-form-validator.d.ts +6 -33
- package/lib/services/mrx-form-validator/validations/callback.validation.d.ts +5 -0
- package/lib/services/mrx-form-validator/validations/email.validation.d.ts +5 -0
- package/lib/services/mrx-form-validator/validations/max-length.validation.d.ts +5 -0
- package/lib/services/mrx-form-validator/validations/max-value.validation.d.ts +5 -0
- package/lib/services/mrx-form-validator/validations/min-length.validation.d.ts +5 -0
- package/lib/services/mrx-form-validator/validations/min-value.validation.d.ts +5 -0
- package/lib/services/mrx-form-validator/validations/pattern.validation.d.ts +5 -0
- package/lib/services/mrx-form-validator/validations/required.validation.d.ts +5 -0
- package/package.json +1 -1
package/fesm2022/myrta-ui.mjs
CHANGED
|
@@ -3371,7 +3371,174 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.11", ngImpo
|
|
|
3371
3371
|
}]
|
|
3372
3372
|
}], ctorParameters: () => [{ type: i1$5.HttpClient }] });
|
|
3373
3373
|
|
|
3374
|
-
|
|
3374
|
+
var ValidationTypesEnum;
|
|
3375
|
+
(function (ValidationTypesEnum) {
|
|
3376
|
+
ValidationTypesEnum["Required"] = "required";
|
|
3377
|
+
ValidationTypesEnum["MaxLength"] = "maxLength";
|
|
3378
|
+
ValidationTypesEnum["MinLength"] = "minLength";
|
|
3379
|
+
ValidationTypesEnum["Email"] = "email";
|
|
3380
|
+
ValidationTypesEnum["Pattern"] = "pattern";
|
|
3381
|
+
ValidationTypesEnum["MaxValue"] = "maxValue";
|
|
3382
|
+
ValidationTypesEnum["MinValue"] = "minValue";
|
|
3383
|
+
ValidationTypesEnum["Callback"] = "callback";
|
|
3384
|
+
})(ValidationTypesEnum || (ValidationTypesEnum = {}));
|
|
3385
|
+
var ValidationOptionsEnum;
|
|
3386
|
+
(function (ValidationOptionsEnum) {
|
|
3387
|
+
ValidationOptionsEnum["Type"] = "type";
|
|
3388
|
+
ValidationOptionsEnum["Messages"] = "messages";
|
|
3389
|
+
})(ValidationOptionsEnum || (ValidationOptionsEnum = {}));
|
|
3390
|
+
var ValidationMethodsEnum;
|
|
3391
|
+
(function (ValidationMethodsEnum) {
|
|
3392
|
+
ValidationMethodsEnum["Submit"] = "submit";
|
|
3393
|
+
ValidationMethodsEnum["Input"] = "input";
|
|
3394
|
+
})(ValidationMethodsEnum || (ValidationMethodsEnum = {}));
|
|
3395
|
+
|
|
3396
|
+
const getErrorMessageHelper = (key, invalidMessages, messages, params) => {
|
|
3397
|
+
const message = messages?.[key] ? messages[key] : invalidMessages[key];
|
|
3398
|
+
if (typeof message === 'function') {
|
|
3399
|
+
return message(params);
|
|
3400
|
+
}
|
|
3401
|
+
else {
|
|
3402
|
+
return message;
|
|
3403
|
+
}
|
|
3404
|
+
};
|
|
3405
|
+
|
|
3406
|
+
const requiredValidation = (value, validations, key, invalidMessages) => {
|
|
3407
|
+
const result = { isValid: true, message: null };
|
|
3408
|
+
if (Array.isArray(value) && validations.type !== 'single' && validations[key]) {
|
|
3409
|
+
value.forEach((field, idx) => {
|
|
3410
|
+
if ((field === '' || field === null || field === undefined)) {
|
|
3411
|
+
result.message = getErrorMessageHelper(key, invalidMessages, validations.messages);
|
|
3412
|
+
result.isValid = false;
|
|
3413
|
+
}
|
|
3414
|
+
});
|
|
3415
|
+
}
|
|
3416
|
+
else if (Array.isArray(value) && validations.type === 'single' && value.length === 0 && validations[key]) {
|
|
3417
|
+
result.message = getErrorMessageHelper(key, invalidMessages, validations.messages);
|
|
3418
|
+
result.isValid = false;
|
|
3419
|
+
}
|
|
3420
|
+
else if ((String(value) === '' || String(value) === 'false' || value === null || value === undefined || String(value) === '<p><br></p>') && validations[key]) {
|
|
3421
|
+
result.message = getErrorMessageHelper(key, invalidMessages, validations.messages);
|
|
3422
|
+
result.isValid = false;
|
|
3423
|
+
}
|
|
3424
|
+
return result;
|
|
3425
|
+
};
|
|
3426
|
+
|
|
3427
|
+
const emailValidation = (value, validations, key, invalidMessages) => {
|
|
3428
|
+
const emailRegExp = /^[a-zA-Z0-9._а-яА-Я-]+@[a-zA-Zа-яА-Я0-9.-]+\.[a-zA-Zа-яА-Я]{2,10}$/;
|
|
3429
|
+
const result = { isValid: true, message: null };
|
|
3430
|
+
if (value && !emailRegExp.test(value)) {
|
|
3431
|
+
result.message = getErrorMessageHelper(key, invalidMessages, validations.messages);
|
|
3432
|
+
result.isValid = false;
|
|
3433
|
+
}
|
|
3434
|
+
return result;
|
|
3435
|
+
};
|
|
3436
|
+
|
|
3437
|
+
const patternValidation = (value, validations, key, invalidMessages) => {
|
|
3438
|
+
const validation = new RegExp(validations[key]);
|
|
3439
|
+
const result = { isValid: true, message: null };
|
|
3440
|
+
if (!validation.test(value)) {
|
|
3441
|
+
result.message = getErrorMessageHelper(key, invalidMessages, validations.messages);
|
|
3442
|
+
result.isValid = false;
|
|
3443
|
+
}
|
|
3444
|
+
return result;
|
|
3445
|
+
};
|
|
3446
|
+
|
|
3447
|
+
const maxLengthValidation = (value, validations, key, invalidMessages) => {
|
|
3448
|
+
const result = { isValid: true, message: null };
|
|
3449
|
+
if (Array.isArray(value) && validations.type === 'single' && value.length > Number(validations[key])) {
|
|
3450
|
+
result.message = getErrorMessageHelper(key, invalidMessages, validations.messages, Number(validations[key]));
|
|
3451
|
+
result.isValid = false;
|
|
3452
|
+
}
|
|
3453
|
+
else if (!Array.isArray(value) && String(value).length > Number(validations[key])) {
|
|
3454
|
+
result.message = getErrorMessageHelper(key, invalidMessages, validations.messages, Number(validations[key]));
|
|
3455
|
+
result.isValid = false;
|
|
3456
|
+
}
|
|
3457
|
+
return result;
|
|
3458
|
+
};
|
|
3459
|
+
|
|
3460
|
+
const minLengthValidation = (value, validations, key, invalidMessages) => {
|
|
3461
|
+
const result = { isValid: true, message: null };
|
|
3462
|
+
if (Array.isArray(value) && validations.type === 'single' && value.length < Number(validations[key])) {
|
|
3463
|
+
result.message = getErrorMessageHelper(key, invalidMessages, validations.messages, Number(validations[key]));
|
|
3464
|
+
result.isValid = false;
|
|
3465
|
+
}
|
|
3466
|
+
else if (!Array.isArray(value) && String(value).length < Number(validations[key]) && !!validations[ValidationTypesEnum.Required]) {
|
|
3467
|
+
result.message = getErrorMessageHelper(key, invalidMessages, validations.messages, Number(validations[key]));
|
|
3468
|
+
result.isValid = false;
|
|
3469
|
+
}
|
|
3470
|
+
return result;
|
|
3471
|
+
};
|
|
3472
|
+
|
|
3473
|
+
const minValueValidation = (value, validations, key, invalidMessages) => {
|
|
3474
|
+
const result = { isValid: true, message: null };
|
|
3475
|
+
if (parseInt(value) < Number(validations[key])) {
|
|
3476
|
+
result.message = getErrorMessageHelper(key, invalidMessages, validations.messages, Number(validations[key]));
|
|
3477
|
+
result.isValid = false;
|
|
3478
|
+
}
|
|
3479
|
+
return result;
|
|
3480
|
+
};
|
|
3481
|
+
|
|
3482
|
+
const maxValueValidation = (value, validations, key, invalidMessages) => {
|
|
3483
|
+
const result = { isValid: true, message: null };
|
|
3484
|
+
if (parseInt(value) > Number(validations[key])) {
|
|
3485
|
+
result.message = getErrorMessageHelper(key, invalidMessages, validations.messages, Number(validations[key]));
|
|
3486
|
+
result.isValid = false;
|
|
3487
|
+
}
|
|
3488
|
+
return result;
|
|
3489
|
+
};
|
|
3490
|
+
|
|
3491
|
+
const callbackValidation = (value, validations, key, invalidMessages) => {
|
|
3492
|
+
const result = { isValid: true, message: null };
|
|
3493
|
+
if (validations[ValidationTypesEnum.Callback] && typeof validations[ValidationTypesEnum.Callback] === 'function') {
|
|
3494
|
+
const validation = validations[ValidationTypesEnum.Callback];
|
|
3495
|
+
const callbackResult = validation(value);
|
|
3496
|
+
if (callbackResult !== true) {
|
|
3497
|
+
result.message = getErrorMessageHelper(key, invalidMessages, validations.messages || { callback: callbackResult });
|
|
3498
|
+
result.isValid = false;
|
|
3499
|
+
}
|
|
3500
|
+
}
|
|
3501
|
+
return result;
|
|
3502
|
+
};
|
|
3503
|
+
|
|
3504
|
+
const INVALID_MESSAGES = {
|
|
3505
|
+
required: () => 'Поле обязательно для заполнения',
|
|
3506
|
+
maxLength: (length) => `Максимальное кол-во символов ${length}`,
|
|
3507
|
+
minLength: (length) => `Минимальное кол-во символов ${length}`,
|
|
3508
|
+
maxValue: (value) => `Максимальное значение ${value}`,
|
|
3509
|
+
minValue: (value) => `Минимальное значение ${value}`,
|
|
3510
|
+
email: () => 'Указан некорректный адрес электронной почты',
|
|
3511
|
+
pattern: () => 'Указано некорректное значение',
|
|
3512
|
+
};
|
|
3513
|
+
|
|
3514
|
+
const getSortingValidationsHelper = (validation) => {
|
|
3515
|
+
const sortedValidatorsConstant = [
|
|
3516
|
+
ValidationTypesEnum.MaxValue,
|
|
3517
|
+
ValidationTypesEnum.MinValue,
|
|
3518
|
+
ValidationTypesEnum.MaxLength,
|
|
3519
|
+
ValidationTypesEnum.MinLength,
|
|
3520
|
+
ValidationTypesEnum.Email,
|
|
3521
|
+
ValidationTypesEnum.Required,
|
|
3522
|
+
ValidationTypesEnum.Pattern,
|
|
3523
|
+
ValidationTypesEnum.Callback,
|
|
3524
|
+
ValidationOptionsEnum.Type,
|
|
3525
|
+
ValidationOptionsEnum.Messages
|
|
3526
|
+
];
|
|
3527
|
+
const sortedValidators = {};
|
|
3528
|
+
for (let key of sortedValidatorsConstant) {
|
|
3529
|
+
if (validation.hasOwnProperty(key)) {
|
|
3530
|
+
sortedValidators[key] = validation[key];
|
|
3531
|
+
}
|
|
3532
|
+
else {
|
|
3533
|
+
if (key === 'type') {
|
|
3534
|
+
validation.type = 'single';
|
|
3535
|
+
sortedValidators.type = 'single';
|
|
3536
|
+
}
|
|
3537
|
+
}
|
|
3538
|
+
}
|
|
3539
|
+
return sortedValidators;
|
|
3540
|
+
};
|
|
3541
|
+
|
|
3375
3542
|
class MrxFormValidator {
|
|
3376
3543
|
_fields = [];
|
|
3377
3544
|
_validations = {};
|
|
@@ -3380,15 +3547,7 @@ class MrxFormValidator {
|
|
|
3380
3547
|
_isInit = false;
|
|
3381
3548
|
_modelClone = {};
|
|
3382
3549
|
_method = 'submit';
|
|
3383
|
-
_invalidMessages =
|
|
3384
|
-
required: () => 'Поле обязательно для заполнения',
|
|
3385
|
-
maxLength: (length) => `Максимальное кол-во символов ${length}`,
|
|
3386
|
-
minLength: (length) => `Минимальное кол-во символов ${length}`,
|
|
3387
|
-
maxValue: (value) => `Максимальное значение ${value}`,
|
|
3388
|
-
minValue: (value) => `Минимальное значение ${value}`,
|
|
3389
|
-
email: () => 'Указан некорректный адрес электронной почты',
|
|
3390
|
-
pattern: () => 'Указано некорректное значение',
|
|
3391
|
-
};
|
|
3550
|
+
_invalidMessages = INVALID_MESSAGES;
|
|
3392
3551
|
constructor(options) {
|
|
3393
3552
|
if (options?.method) {
|
|
3394
3553
|
this._method = options.method;
|
|
@@ -3397,21 +3556,6 @@ class MrxFormValidator {
|
|
|
3397
3556
|
this._invalidMessages = { ...this._invalidMessages, ...options.messages };
|
|
3398
3557
|
}
|
|
3399
3558
|
}
|
|
3400
|
-
sortValidators(validations) {
|
|
3401
|
-
const sortedValidatorsConstant = ['maxValue', 'minValue', 'minLength', 'maxLength', 'email', 'pattern', 'messages', 'required', 'type'];
|
|
3402
|
-
const sortedValidators = {};
|
|
3403
|
-
for (let key of sortedValidatorsConstant) {
|
|
3404
|
-
if (validations.hasOwnProperty(key)) {
|
|
3405
|
-
sortedValidators[key] = validations[key];
|
|
3406
|
-
}
|
|
3407
|
-
else {
|
|
3408
|
-
if (key === 'type') {
|
|
3409
|
-
validations.type = 'multi';
|
|
3410
|
-
}
|
|
3411
|
-
}
|
|
3412
|
-
}
|
|
3413
|
-
return sortedValidators;
|
|
3414
|
-
}
|
|
3415
3559
|
get errors() {
|
|
3416
3560
|
return this._errors;
|
|
3417
3561
|
}
|
|
@@ -3436,180 +3580,92 @@ class MrxFormValidator {
|
|
|
3436
3580
|
}
|
|
3437
3581
|
return namesUpdatedProperties;
|
|
3438
3582
|
}
|
|
3439
|
-
validateField(
|
|
3583
|
+
validateField(value, name, validations, validateEmptyValue = false, silent = false) {
|
|
3584
|
+
if (!validateEmptyValue && (value.length === 0)) {
|
|
3585
|
+
return;
|
|
3586
|
+
}
|
|
3440
3587
|
for (let key in validations) {
|
|
3441
3588
|
switch (key) {
|
|
3442
|
-
case
|
|
3443
|
-
|
|
3444
|
-
|
|
3445
|
-
|
|
3446
|
-
|
|
3447
|
-
fieldValue.forEach((field, idx) => {
|
|
3448
|
-
if ((field === '' || field === null || field === undefined) && key === 'required') {
|
|
3449
|
-
if (validations.messages?.[key]) {
|
|
3450
|
-
this._errors[fieldName][idx] = validations.messages[key];
|
|
3451
|
-
}
|
|
3452
|
-
else {
|
|
3453
|
-
this._errors[fieldName] = { ...this._errors[fieldName], [idx]: this._invalidMessages[key]() };
|
|
3454
|
-
}
|
|
3455
|
-
this._isValid = false;
|
|
3456
|
-
}
|
|
3457
|
-
});
|
|
3458
|
-
}
|
|
3459
|
-
else if (Array.isArray(fieldValue) && validations.type === 'single' && fieldValue.length === 0) {
|
|
3460
|
-
if (validations.messages?.[key]) {
|
|
3461
|
-
this._errors[fieldName] = validations.messages[key];
|
|
3462
|
-
}
|
|
3463
|
-
else {
|
|
3464
|
-
this._errors[fieldName] = this._invalidMessages[key]();
|
|
3465
|
-
}
|
|
3466
|
-
this._isValid = false;
|
|
3467
|
-
}
|
|
3468
|
-
else if (String(fieldValue) === '' || String(fieldValue) === 'false' || fieldValue === null || fieldValue === undefined || String(fieldValue) === '<p><br></p>') {
|
|
3469
|
-
if (validations.messages?.[key]) {
|
|
3470
|
-
this._errors[fieldName] = validations.messages[key];
|
|
3471
|
-
}
|
|
3472
|
-
else {
|
|
3473
|
-
this._errors[fieldName] = this._invalidMessages[key]();
|
|
3474
|
-
}
|
|
3475
|
-
this._isValid = false;
|
|
3589
|
+
case ValidationTypesEnum.Required:
|
|
3590
|
+
const requiredRes = requiredValidation(value, validations, key, this._invalidMessages);
|
|
3591
|
+
this._isValid = requiredRes.isValid;
|
|
3592
|
+
if (!silent && !this._errors[name]) {
|
|
3593
|
+
this._errors[name] = requiredRes.message;
|
|
3476
3594
|
}
|
|
3477
3595
|
break;
|
|
3478
|
-
case
|
|
3479
|
-
|
|
3480
|
-
|
|
3596
|
+
case ValidationTypesEnum.Email:
|
|
3597
|
+
const emailRes = emailValidation(value, validations, key, this._invalidMessages);
|
|
3598
|
+
this._isValid = emailRes.isValid;
|
|
3599
|
+
if (!silent && !this._errors[name]) {
|
|
3600
|
+
this._errors[name] = emailRes.message;
|
|
3481
3601
|
}
|
|
3482
|
-
|
|
3483
|
-
|
|
3484
|
-
|
|
3485
|
-
|
|
3486
|
-
|
|
3487
|
-
|
|
3488
|
-
}
|
|
3489
|
-
this._isValid = false;
|
|
3602
|
+
break;
|
|
3603
|
+
case ValidationTypesEnum.Pattern:
|
|
3604
|
+
const patternRes = patternValidation(value, validations, key, this._invalidMessages);
|
|
3605
|
+
this._isValid = patternRes.isValid;
|
|
3606
|
+
if (!silent && !this._errors[name]) {
|
|
3607
|
+
this._errors[name] = patternRes.message;
|
|
3490
3608
|
}
|
|
3491
3609
|
break;
|
|
3492
|
-
case
|
|
3493
|
-
|
|
3494
|
-
|
|
3495
|
-
|
|
3496
|
-
|
|
3497
|
-
else {
|
|
3498
|
-
this._errors[fieldName] = this._invalidMessages[key]();
|
|
3499
|
-
}
|
|
3500
|
-
this._isValid = false;
|
|
3610
|
+
case ValidationTypesEnum.MinLength:
|
|
3611
|
+
const minLengthRes = minLengthValidation(value, validations, key, this._invalidMessages);
|
|
3612
|
+
this._isValid = minLengthRes.isValid;
|
|
3613
|
+
if (!silent && !this._errors[name]) {
|
|
3614
|
+
this._errors[name] = minLengthRes.message;
|
|
3501
3615
|
}
|
|
3502
3616
|
break;
|
|
3503
|
-
case
|
|
3504
|
-
|
|
3505
|
-
|
|
3506
|
-
|
|
3507
|
-
|
|
3508
|
-
else {
|
|
3509
|
-
this._errors[fieldName] = this._invalidMessages[key](Number(validations[key]));
|
|
3510
|
-
}
|
|
3511
|
-
this._isValid = false;
|
|
3617
|
+
case ValidationTypesEnum.MaxLength:
|
|
3618
|
+
const maxLengthRes = maxLengthValidation(value, validations, key, this._invalidMessages);
|
|
3619
|
+
this._isValid = maxLengthRes.isValid;
|
|
3620
|
+
if (!silent && !this._errors[name]) {
|
|
3621
|
+
this._errors[name] = maxLengthRes.message;
|
|
3512
3622
|
}
|
|
3513
3623
|
break;
|
|
3514
|
-
case
|
|
3515
|
-
|
|
3516
|
-
|
|
3517
|
-
|
|
3518
|
-
|
|
3519
|
-
else {
|
|
3520
|
-
this._errors[fieldName] = this._invalidMessages[key](Number(validations[key]));
|
|
3521
|
-
}
|
|
3522
|
-
this._isValid = false;
|
|
3624
|
+
case ValidationTypesEnum.MinValue:
|
|
3625
|
+
const minValueRes = minValueValidation(value, validations, key, this._invalidMessages);
|
|
3626
|
+
this._isValid = minValueRes.isValid;
|
|
3627
|
+
if (!silent && !this._errors[name]) {
|
|
3628
|
+
this._errors[name] = minValueRes.message;
|
|
3523
3629
|
}
|
|
3524
3630
|
break;
|
|
3525
|
-
case
|
|
3526
|
-
|
|
3527
|
-
|
|
3528
|
-
|
|
3529
|
-
|
|
3530
|
-
else {
|
|
3531
|
-
this._errors[fieldName] = this._invalidMessages[key](Number(validations[key]));
|
|
3532
|
-
}
|
|
3533
|
-
this._isValid = false;
|
|
3631
|
+
case ValidationTypesEnum.MaxValue:
|
|
3632
|
+
const maxValueRes = maxValueValidation(value, validations, key, this._invalidMessages);
|
|
3633
|
+
this._isValid = maxValueRes.isValid;
|
|
3634
|
+
if (!silent && !this._errors[name]) {
|
|
3635
|
+
this._errors[name] = maxValueRes.message;
|
|
3534
3636
|
}
|
|
3535
3637
|
break;
|
|
3536
|
-
case
|
|
3537
|
-
|
|
3538
|
-
|
|
3539
|
-
|
|
3540
|
-
|
|
3541
|
-
else {
|
|
3542
|
-
this._errors[fieldName] = this._invalidMessages[key](Number(validations[key]));
|
|
3543
|
-
}
|
|
3544
|
-
this._isValid = false;
|
|
3638
|
+
case ValidationTypesEnum.Callback:
|
|
3639
|
+
const callbackRes = callbackValidation(value, validations, key, this._invalidMessages);
|
|
3640
|
+
this._isValid = callbackRes.isValid;
|
|
3641
|
+
if (!silent && !this._errors[name]) {
|
|
3642
|
+
this._errors[name] = callbackRes.message;
|
|
3545
3643
|
}
|
|
3546
3644
|
break;
|
|
3547
3645
|
}
|
|
3548
3646
|
}
|
|
3549
3647
|
}
|
|
3550
|
-
|
|
3551
|
-
|
|
3552
|
-
|
|
3553
|
-
|
|
3554
|
-
|
|
3555
|
-
|
|
3556
|
-
}
|
|
3557
|
-
if (Array.isArray(fieldValue)) {
|
|
3558
|
-
fieldValue.forEach((field, idx) => {
|
|
3559
|
-
if ((field === '' || field === null || field === undefined) && key === 'required') {
|
|
3560
|
-
this._isValid = false;
|
|
3561
|
-
}
|
|
3562
|
-
});
|
|
3563
|
-
}
|
|
3564
|
-
else if (Array.isArray(fieldValue) && validations.type === 'single' && fieldValue.length === 0) {
|
|
3565
|
-
this._isValid = false;
|
|
3566
|
-
}
|
|
3567
|
-
else if (String(fieldValue) === '' || String(fieldValue) === 'false' || fieldValue === null || fieldValue === undefined || String(fieldValue) === '<p><br></p>') {
|
|
3568
|
-
this._isValid = false;
|
|
3569
|
-
}
|
|
3570
|
-
break;
|
|
3571
|
-
case 'email':
|
|
3572
|
-
if (!validations[key]) {
|
|
3573
|
-
continue;
|
|
3574
|
-
}
|
|
3575
|
-
if (!emailRegExp.test(fieldValue)) {
|
|
3576
|
-
this._isValid = false;
|
|
3577
|
-
}
|
|
3578
|
-
break;
|
|
3579
|
-
case 'pattern':
|
|
3580
|
-
if (!validations[key]?.test(fieldValue)) {
|
|
3581
|
-
this._isValid = false;
|
|
3582
|
-
}
|
|
3583
|
-
break;
|
|
3584
|
-
case 'minLength':
|
|
3585
|
-
if (String(fieldValue).length < Number(validations[key]) && !!validations['required']) {
|
|
3586
|
-
this._isValid = false;
|
|
3587
|
-
}
|
|
3588
|
-
break;
|
|
3589
|
-
case 'maxLength':
|
|
3590
|
-
if (String(fieldValue).length > Number(validations[key])) {
|
|
3591
|
-
this._isValid = false;
|
|
3592
|
-
}
|
|
3593
|
-
break;
|
|
3594
|
-
case 'maxValue':
|
|
3595
|
-
if (parseInt(fieldValue) > Number(validations[key]) && !!validations['required']) {
|
|
3596
|
-
this._isValid = false;
|
|
3597
|
-
}
|
|
3598
|
-
break;
|
|
3599
|
-
case 'minValue':
|
|
3600
|
-
if (parseInt(fieldValue) < Number(validations[key])) {
|
|
3601
|
-
this._isValid = false;
|
|
3602
|
-
}
|
|
3603
|
-
break;
|
|
3648
|
+
_checkErrors(errors) {
|
|
3649
|
+
let isValid = true;
|
|
3650
|
+
for (let error in errors) {
|
|
3651
|
+
if (!!errors[error]) {
|
|
3652
|
+
isValid = !errors[error];
|
|
3653
|
+
break;
|
|
3604
3654
|
}
|
|
3605
3655
|
}
|
|
3656
|
+
return isValid;
|
|
3606
3657
|
}
|
|
3607
3658
|
initFields(fields, validations) {
|
|
3608
3659
|
this.fields = cloneDeep(fields);
|
|
3609
3660
|
this._validations = validations;
|
|
3610
3661
|
this._modelClone = cloneDeep(fields);
|
|
3662
|
+
for (let key in this._errors) {
|
|
3663
|
+
if (!fields.hasOwnProperty(key)) {
|
|
3664
|
+
delete this._errors[key];
|
|
3665
|
+
}
|
|
3666
|
+
}
|
|
3611
3667
|
for (let key in validations) {
|
|
3612
|
-
this._validations[key] =
|
|
3668
|
+
this._validations[key] = getSortingValidationsHelper(validations[key]);
|
|
3613
3669
|
this.errors[key] = null;
|
|
3614
3670
|
}
|
|
3615
3671
|
this._isInit = true;
|
|
@@ -3620,34 +3676,49 @@ class MrxFormValidator {
|
|
|
3620
3676
|
this._modelClone = cloneDeep(fields);
|
|
3621
3677
|
this.getNamesUpdatedProperties(this._fields, fields).forEach((name) => {
|
|
3622
3678
|
this._errors[name] = null;
|
|
3623
|
-
this._method ===
|
|
3679
|
+
if (this._method === ValidationMethodsEnum.Input) {
|
|
3680
|
+
this.validateField(fields[name], name, this._validations[name], true);
|
|
3681
|
+
}
|
|
3624
3682
|
});
|
|
3625
3683
|
}
|
|
3626
3684
|
this.fields = cloneDeep(fields);
|
|
3627
3685
|
}
|
|
3686
|
+
initFieldChanged(fields, fieldName) {
|
|
3687
|
+
if (this._isInit) {
|
|
3688
|
+
this._isValid = true;
|
|
3689
|
+
if (fields.hasOwnProperty(fieldName)) {
|
|
3690
|
+
this._modelClone[fieldName] = fields[fieldName];
|
|
3691
|
+
}
|
|
3692
|
+
this._errors[fieldName] = null;
|
|
3693
|
+
this.validateField(this._modelClone[fieldName], fieldName, this._validations[fieldName], false);
|
|
3694
|
+
}
|
|
3695
|
+
}
|
|
3696
|
+
isValid() {
|
|
3697
|
+
for (let key in this._validations) {
|
|
3698
|
+
this.errors[key] = null;
|
|
3699
|
+
this.validateField(this._fields[key], key, this._validations[key], true);
|
|
3700
|
+
}
|
|
3701
|
+
return this._checkErrors(this.errors);
|
|
3702
|
+
}
|
|
3703
|
+
// TODO Вырезать в будущем
|
|
3628
3704
|
initModelChangedFromField(field, fieldName) {
|
|
3629
3705
|
if (this._isInit) {
|
|
3630
3706
|
this._isValid = true;
|
|
3631
3707
|
this._modelClone[fieldName] = field;
|
|
3632
3708
|
this.getNamesUpdatedProperties(this._fields, this._modelClone).forEach((name) => {
|
|
3633
3709
|
this._errors[name] = null;
|
|
3634
|
-
this._method ===
|
|
3710
|
+
if (this._method === ValidationMethodsEnum.Input) {
|
|
3711
|
+
this.validateField(this._modelClone[name], name, this._validations[name], true);
|
|
3712
|
+
}
|
|
3635
3713
|
});
|
|
3636
3714
|
}
|
|
3637
3715
|
this.fields = this._modelClone;
|
|
3638
3716
|
}
|
|
3639
|
-
|
|
3640
|
-
this._isValid = true;
|
|
3641
|
-
for (let key in this._validations) {
|
|
3642
|
-
this.errors[key] = null;
|
|
3643
|
-
this.validateField(this._fields[key], key, this._validations[key]);
|
|
3644
|
-
}
|
|
3645
|
-
return this._isValid;
|
|
3646
|
-
}
|
|
3717
|
+
// TODO Вырезать в будущем
|
|
3647
3718
|
isHiddenValid() {
|
|
3648
3719
|
this._isValid = true;
|
|
3649
3720
|
for (let key in this._validations) {
|
|
3650
|
-
this.
|
|
3721
|
+
this.validateField(this._fields[key], key, this._validations[key], true, true);
|
|
3651
3722
|
}
|
|
3652
3723
|
return this._isValid;
|
|
3653
3724
|
}
|
|
@@ -15910,5 +15981,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.11", ngImpo
|
|
|
15910
15981
|
* Generated bundle index. Do not edit.
|
|
15911
15982
|
*/
|
|
15912
15983
|
|
|
15913
|
-
export { AlertColorClasses, AlertComponent, AlertIconClasses, AlertModule, BadgeColorClassesEnum, BadgeComponent, BadgeGroupComponent, BadgeSizeEnum, BadgeTagTypeClassesEnum, BadgeTargetTypesEnum, BadgeTypeEnum, BadgesModule, BreadcrumbsComponent, BreadcrumbsModule, BreadcrumbsTypeEnum, ButtonColorsEnum, ButtonComponent, ButtonIconPositionEnum, ButtonModule, ButtonSizesEnum, ButtonTypesEnum, CdkTooltipDirective, CdkTooltipModule, CharsLeftComponent, CharsLeftModule, CheckboxComponent, CheckboxGroupComponent, CheckboxGroupModule, CheckboxModule, CheckboxTypesEnum, ColumnComponent, ContentWrapperComponent, ContentWrapperModule, ContentWrapperTypeEnum, ControlsItemComponent, ControlsVisibilityEnum, ControlsWrapperComponent, ControlsWrapperModule, CountryISO$1 as CountryISO, CurrencyModule, CurrencyPipe, DateFormatModule, DateFormatPipe, DateTimeFormatPipe, DefaultPagerSettings, DropdownComponent, DropdownModule, EditorComponent, EditorModule, ErrorMessageComponent, ErrorMessageModule, FileUploadService, GalleryComponent, GalleryModule, HideAfterClickDirective, HintErrorMessageComponent, HintErrorMessageModule, IconButtonComponent, IconButtonModule, IconButtonSizeEnum, IconButtonStateEnum, IconButtonTypeEnum, InputDateSizesEnum$2 as InputDateSizesEnum, InputDateTimeComponent, InputDateTimeModule, InputDatepickerComponent, InputDatepickerModule, InputFileComponent, InputFileImageComponent, InputFileImageModule, InputFileImageTypeEnum, InputFileModule, InputNumberComponent, InputNumberModule, InputNumberSizesEnum, InputOptComponent, InputOptModule, InputPasswordComponent, InputPasswordModule, InputPasswordSizesEnum, InputPhoneComponent, InputPhoneModule, InputSearchComponent, InputSearchModule, InputSearchSizesEnum, InputSelectComponent, InputSelectModule, InputSelectSizeEnum, InputTelComponent, InputTelModule, InputTextComponent, InputTextIconColorEnum, InputTextModule, InputTextSizesEnum, InputTextareaComponent, InputTextareaModule, InputTextareaSizesEnum, InputTimepickerComponent, InputTimepickerModule, LabelComponent, LabelModule, LinkComponent, LinkModule, LinkSizesEnum, LinkTargetTypesEnum, LinkTypesEnum, LoaderColorEnum, LoaderComponent, LoaderModule, LoaderSizesEnum, MODAL_CONFIG, MODAL_DATA, ModalAlignButtonsEnum, ModalColorEnum, ModalComponent, ModalModule, ModalRef, ModalService, ModalServiceComponent, ModalServiceModule, ModalSizesEnum, MrxAutoSaveActionsEnum, MrxAutosaveService, MrxFormValidator, NgxOtpBehavior, PagesNavComponent, PagesNavEnum, PagesNavModule, PaginatorComponent, PaginatorModule, PaginatorPositionCss, PdfViewerComponent, PdfViewerComponentModule, PhoneFormatModule, PhoneFormatPipe, PreviewEnum, ProgressClasses, ProgressComponent, ProgressModule, RadioComponent, RadioGroupComponent, RadioGroupModule, RadioModule, RadioTypesEnum, RatingComponent, RatingModule, RatingSizesEnum, RatingValueSizesEnum, RatingWrapperSizesEnum, SafeModule, SafePipe, SaveStateComponent, SaveStateModule, SaveStoreModule, StepperClasses, StepperComponent, StepperModule, SwitchComponent, SwitchModule, SwitchSizeEnum, SwitchTypeEnum, TabComponent, TableComponent, TableModule, TableTypeEnum, TabsClasses, TabsGroupComponent, TabsModule, TabsTypesClasses, Timezone$1 as Timezone, ToasterPosition, ToasterService, ToasterServiceModule, ToasterType, Tooltip, TooltipComponent, TooltipModule, TooltipService, TooltipTextPositionEnum, TooltipTriggerComponent, TooltipTriggerEnum, TruncateDirective, TruncateDirectiveModule, TruncateModule, TruncatePipe, TruncateTextComponent, TruncateTextModule, WarningMessageComponent, WarningMessageModule, WidgetWrapperComponent, WidgetWrapperModule, autosaveAddId, autosaveError, autosaveErrorFor, autosaveStart, autosaveStartFor, autosaveStop, autosaveStopFor, autosaveSuccess, autosaveSuccessFor, convertBase64ToFile, dateTimeFormat, defaultConfig, defaultCustomConfig,
|
|
15984
|
+
export { AlertColorClasses, AlertComponent, AlertIconClasses, AlertModule, BadgeColorClassesEnum, BadgeComponent, BadgeGroupComponent, BadgeSizeEnum, BadgeTagTypeClassesEnum, BadgeTargetTypesEnum, BadgeTypeEnum, BadgesModule, BreadcrumbsComponent, BreadcrumbsModule, BreadcrumbsTypeEnum, ButtonColorsEnum, ButtonComponent, ButtonIconPositionEnum, ButtonModule, ButtonSizesEnum, ButtonTypesEnum, CdkTooltipDirective, CdkTooltipModule, CharsLeftComponent, CharsLeftModule, CheckboxComponent, CheckboxGroupComponent, CheckboxGroupModule, CheckboxModule, CheckboxTypesEnum, ColumnComponent, ContentWrapperComponent, ContentWrapperModule, ContentWrapperTypeEnum, ControlsItemComponent, ControlsVisibilityEnum, ControlsWrapperComponent, ControlsWrapperModule, CountryISO$1 as CountryISO, CurrencyModule, CurrencyPipe, DateFormatModule, DateFormatPipe, DateTimeFormatPipe, DefaultPagerSettings, DropdownComponent, DropdownModule, EditorComponent, EditorModule, ErrorMessageComponent, ErrorMessageModule, FileUploadService, GalleryComponent, GalleryModule, HideAfterClickDirective, HintErrorMessageComponent, HintErrorMessageModule, IconButtonComponent, IconButtonModule, IconButtonSizeEnum, IconButtonStateEnum, IconButtonTypeEnum, InputDateSizesEnum$2 as InputDateSizesEnum, InputDateTimeComponent, InputDateTimeModule, InputDatepickerComponent, InputDatepickerModule, InputFileComponent, InputFileImageComponent, InputFileImageModule, InputFileImageTypeEnum, InputFileModule, InputNumberComponent, InputNumberModule, InputNumberSizesEnum, InputOptComponent, InputOptModule, InputPasswordComponent, InputPasswordModule, InputPasswordSizesEnum, InputPhoneComponent, InputPhoneModule, InputSearchComponent, InputSearchModule, InputSearchSizesEnum, InputSelectComponent, InputSelectModule, InputSelectSizeEnum, InputTelComponent, InputTelModule, InputTextComponent, InputTextIconColorEnum, InputTextModule, InputTextSizesEnum, InputTextareaComponent, InputTextareaModule, InputTextareaSizesEnum, InputTimepickerComponent, InputTimepickerModule, LabelComponent, LabelModule, LinkComponent, LinkModule, LinkSizesEnum, LinkTargetTypesEnum, LinkTypesEnum, LoaderColorEnum, LoaderComponent, LoaderModule, LoaderSizesEnum, MODAL_CONFIG, MODAL_DATA, ModalAlignButtonsEnum, ModalColorEnum, ModalComponent, ModalModule, ModalRef, ModalService, ModalServiceComponent, ModalServiceModule, ModalSizesEnum, MrxAutoSaveActionsEnum, MrxAutosaveService, MrxFormValidator, NgxOtpBehavior, PagesNavComponent, PagesNavEnum, PagesNavModule, PaginatorComponent, PaginatorModule, PaginatorPositionCss, PdfViewerComponent, PdfViewerComponentModule, PhoneFormatModule, PhoneFormatPipe, PreviewEnum, ProgressClasses, ProgressComponent, ProgressModule, RadioComponent, RadioGroupComponent, RadioGroupModule, RadioModule, RadioTypesEnum, RatingComponent, RatingModule, RatingSizesEnum, RatingValueSizesEnum, RatingWrapperSizesEnum, SafeModule, SafePipe, SaveStateComponent, SaveStateModule, SaveStoreModule, StepperClasses, StepperComponent, StepperModule, SwitchComponent, SwitchModule, SwitchSizeEnum, SwitchTypeEnum, TabComponent, TableComponent, TableModule, TableTypeEnum, TabsClasses, TabsGroupComponent, TabsModule, TabsTypesClasses, Timezone$1 as Timezone, ToasterPosition, ToasterService, ToasterServiceModule, ToasterType, Tooltip, TooltipComponent, TooltipModule, TooltipService, TooltipTextPositionEnum, TooltipTriggerComponent, TooltipTriggerEnum, TruncateDirective, TruncateDirectiveModule, TruncateModule, TruncatePipe, TruncateTextComponent, TruncateTextModule, ValidationMethodsEnum, ValidationOptionsEnum, ValidationTypesEnum, WarningMessageComponent, WarningMessageModule, WidgetWrapperComponent, WidgetWrapperModule, autosaveAddId, autosaveError, autosaveErrorFor, autosaveStart, autosaveStartFor, autosaveStop, autosaveStopFor, autosaveSuccess, autosaveSuccessFor, convertBase64ToFile, dateTimeFormat, defaultConfig, defaultCustomConfig, formatBytes, formattingDateRange, formattingIsoToString, getBase64FromUrl, getHashCode, sHashCode, selectFields, selectMrxAutoSaveState, sliceDate, toBytes, toDate, toNumberFormat, wordForm };
|
|
15914
15985
|
//# sourceMappingURL=myrta-ui.mjs.map
|