@arsedizioni/ars-utils 22.5.46 → 22.5.48
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/fesm2022/arsedizioni-ars-utils-core.validators.mjs +18 -139
- package/fesm2022/arsedizioni-ars-utils-core.validators.mjs.map +1 -1
- package/fesm2022/arsedizioni-ars-utils-ui.dialogs.select.mjs +100 -14
- package/fesm2022/arsedizioni-ars-utils-ui.dialogs.select.mjs.map +1 -1
- package/fesm2022/arsedizioni-ars-utils-ui.mjs.map +1 -1
- package/package.json +1 -1
- package/types/arsedizioni-ars-utils-core.validators.d.ts +9 -64
- package/types/arsedizioni-ars-utils-ui.d.ts +31 -2
- package/types/arsedizioni-ars-utils-ui.dialogs.select.d.ts +49 -3
|
@@ -3,7 +3,7 @@ import { input, Directive, forwardRef, effect, inject, DestroyRef } from '@angul
|
|
|
3
3
|
import { NG_VALIDATORS } from '@angular/forms';
|
|
4
4
|
import { SystemUtils } from '@arsedizioni/ars-utils/core';
|
|
5
5
|
import { endOfDay } from 'date-fns';
|
|
6
|
-
import { validate
|
|
6
|
+
import { validate } from '@angular/forms/signals';
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Directive that delegates validation to an externally provided validator function.
|
|
@@ -664,37 +664,20 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.4", ngImpor
|
|
|
664
664
|
/**
|
|
665
665
|
* @file emptiness.ts
|
|
666
666
|
*
|
|
667
|
-
* The single definition of "empty"
|
|
668
|
-
*
|
|
669
|
-
*
|
|
670
|
-
*
|
|
667
|
+
* The single definition of "empty" behind the `notEmpty` rule, in both its flavours: the
|
|
668
|
+
* template-driven directive and the signal-form validator. It lives apart from either of them so
|
|
669
|
+
* that the two faces of the same rule cannot drift, and it pulls in nothing — not
|
|
670
|
+
* `@angular/forms`, not `@angular/core`.
|
|
671
671
|
*/
|
|
672
|
-
/**
|
|
673
|
-
* Tells whether a value carries nothing at all.
|
|
674
|
-
*
|
|
675
|
-
* Nullish, the empty string and the empty array all count as missing; anything else does not,
|
|
676
|
-
* including `0` and `false`, which are legitimate values a form can hold.
|
|
677
|
-
*
|
|
678
|
-
* @param value - The value to inspect.
|
|
679
|
-
* @returns `true` when the value is absent, an empty string or an empty array.
|
|
680
|
-
*/
|
|
681
|
-
function isMissingValue(value) {
|
|
682
|
-
if (value === undefined || value === null)
|
|
683
|
-
return true;
|
|
684
|
-
if (typeof value === 'string')
|
|
685
|
-
return value.length === 0;
|
|
686
|
-
if (Array.isArray(value))
|
|
687
|
-
return value.length === 0;
|
|
688
|
-
return false;
|
|
689
|
-
}
|
|
690
672
|
/**
|
|
691
673
|
* Tells whether a value is what the `notEmpty` rule rejects: a string made of whitespace alone,
|
|
692
674
|
* or an array with no elements.
|
|
693
675
|
*
|
|
694
676
|
* An absent value and an empty string are deliberately NOT rejected: declaring a field mandatory
|
|
695
|
-
* is the job of `required()
|
|
696
|
-
*
|
|
697
|
-
*
|
|
677
|
+
* is the job of `required()`, and a blank field would otherwise raise two errors saying the same
|
|
678
|
+
* thing. The empty array is the one exception, because there it IS the only shape emptiness can
|
|
679
|
+
* take — a multi-select never holds `''`, and Angular's own `required()` does not see `[]` as
|
|
680
|
+
* empty, so nothing else would catch it.
|
|
698
681
|
*
|
|
699
682
|
* @param value - The value to inspect.
|
|
700
683
|
* @returns `true` when the value is a whitespace-only string or an empty array.
|
|
@@ -712,8 +695,8 @@ function isBlankValue(value) {
|
|
|
712
695
|
* nor an empty array. Apply `notEmpty` to a text input where non-blank content is required, or
|
|
713
696
|
* to a multi-value control that must carry at least one entry.
|
|
714
697
|
*
|
|
715
|
-
* A value that is simply absent passes: saying "obbligatorio" is the job of `required`,
|
|
716
|
-
*
|
|
698
|
+
* A value that is simply absent passes: saying "obbligatorio" is the job of `required`, which is
|
|
699
|
+
* declared next to this one when both rules belong on the same control.
|
|
717
700
|
*/
|
|
718
701
|
class NotEmptyValidatorDirective {
|
|
719
702
|
/**
|
|
@@ -749,63 +732,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.4", ngImpor
|
|
|
749
732
|
}]
|
|
750
733
|
}] });
|
|
751
734
|
|
|
752
|
-
/**
|
|
753
|
-
* Directive that validates that a control carries actual content: present AND not blank.
|
|
754
|
-
* Apply `requiredNotEmpty` where `required notEmpty` would otherwise be spelled out together.
|
|
755
|
-
*
|
|
756
|
-
* It raises the very errors those two rules raise — `required` when the value is missing, an
|
|
757
|
-
* empty string or an empty array, `notEmpty` when a value is there but made of whitespace alone —
|
|
758
|
-
* so existing error messages and `getFieldErrorMessage` keep working untouched, and the user
|
|
759
|
-
* still reads "Obbligatorio" rather than the vaguer "Non può essere vuoto".
|
|
760
|
-
*
|
|
761
|
-
* IMPORTANT, on a Material field: this directive does NOT draw the asterisk. `MatInput` reads its
|
|
762
|
-
* own `required` input first and falls back to `hasValidator(Validators.required)`, which no
|
|
763
|
-
* directive-provided validator can satisfy — the validators of a template-driven control are
|
|
764
|
-
* merged into one composed function before they get there. Keep writing `required` on the
|
|
765
|
-
* control next to this one: the two produce the same `{ required: true }` key, so the errors
|
|
766
|
-
* merge and nothing is reported twice.
|
|
767
|
-
*
|
|
768
|
-
* `aria-required` is set here so that assistive technology is told the truth even where the
|
|
769
|
-
* `required` attribute is absent.
|
|
770
|
-
*/
|
|
771
|
-
class RequiredNotEmptyValidatorDirective {
|
|
772
|
-
/**
|
|
773
|
-
* Validates that the control value is present and carries content.
|
|
774
|
-
* @param control - The form control to validate.
|
|
775
|
-
* @returns `{ required: true }` when nothing was entered, `{ notEmpty: true }` when the value
|
|
776
|
-
* is blank, `null` when the value is acceptable.
|
|
777
|
-
*/
|
|
778
|
-
validate(control) {
|
|
779
|
-
const input = control?.value;
|
|
780
|
-
if (isMissingValue(input))
|
|
781
|
-
return { required: true };
|
|
782
|
-
return isBlankValue(input) ? { notEmpty: true } : null;
|
|
783
|
-
}
|
|
784
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.4", ngImport: i0, type: RequiredNotEmptyValidatorDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
|
|
785
|
-
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "22.1.4", type: RequiredNotEmptyValidatorDirective, isStandalone: true, selector: "[requiredNotEmpty]", host: { properties: { "attr.aria-required": "true" } }, providers: [
|
|
786
|
-
{
|
|
787
|
-
provide: NG_VALIDATORS,
|
|
788
|
-
useExisting: forwardRef(() => RequiredNotEmptyValidatorDirective),
|
|
789
|
-
multi: true,
|
|
790
|
-
},
|
|
791
|
-
], ngImport: i0 }); }
|
|
792
|
-
}
|
|
793
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.4", ngImport: i0, type: RequiredNotEmptyValidatorDirective, decorators: [{
|
|
794
|
-
type: Directive,
|
|
795
|
-
args: [{
|
|
796
|
-
selector: "[requiredNotEmpty]",
|
|
797
|
-
host: { '[attr.aria-required]': 'true' },
|
|
798
|
-
providers: [
|
|
799
|
-
{
|
|
800
|
-
provide: NG_VALIDATORS,
|
|
801
|
-
useExisting: forwardRef(() => RequiredNotEmptyValidatorDirective),
|
|
802
|
-
multi: true,
|
|
803
|
-
},
|
|
804
|
-
],
|
|
805
|
-
standalone: true,
|
|
806
|
-
}]
|
|
807
|
-
}] });
|
|
808
|
-
|
|
809
735
|
/**
|
|
810
736
|
* Default texts of the rules declared here, in one place so that the validators and the fallback
|
|
811
737
|
* map of `SignalsUtils.getFieldErrorMessage` cannot drift apart: a rule added below without a
|
|
@@ -822,8 +748,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.4", ngImpor
|
|
|
822
748
|
*/
|
|
823
749
|
const MIN_VALID_YEAR = 1970;
|
|
824
750
|
const ARS_VALIDATOR_MESSAGES = {
|
|
825
|
-
// Produced by the Angular built-in `required()` and by {@link requiredNotEmpty}. It sits here,
|
|
826
|
-
// and no longer among the built-in fallbacks below, so that the text exists exactly once.
|
|
827
751
|
required: 'Obbligatorio',
|
|
828
752
|
guid: 'Ticket non riconosciuto',
|
|
829
753
|
password: 'Password non sufficientemente robusta',
|
|
@@ -893,12 +817,16 @@ function password(path, config) {
|
|
|
893
817
|
* The signal-form counterpart of `NotEmptyValidatorDirective`, sharing its predicate through
|
|
894
818
|
* {@link isBlankValue}: a blank string and an empty array are errors, an absent value is not.
|
|
895
819
|
* That last part is not an oversight — saying "obbligatorio" belongs to `required()`, and a field
|
|
896
|
-
* that is merely blank would otherwise raise two errors that mean the same thing.
|
|
897
|
-
*
|
|
820
|
+
* that is merely blank would otherwise raise two errors that mean the same thing. Declare the two
|
|
821
|
+
* together when a field must be both present and non-blank.
|
|
898
822
|
*
|
|
899
823
|
* Replaces the `pattern(p.x, /\S/)` workaround: same rule, but the intent is in the name and the
|
|
900
824
|
* error kind is `notEmpty` rather than `pattern`.
|
|
901
825
|
*
|
|
826
|
+
* On a multi-value field this rule is the ONLY one that sees an empty selection: Angular's
|
|
827
|
+
* `required()` treats emptiness as `'' | false | null | undefined`, so an empty array walks past
|
|
828
|
+
* it. Give it a message of its own there, because the default one talks about whitespace.
|
|
829
|
+
*
|
|
902
830
|
* @param path - Path of the field to validate.
|
|
903
831
|
* @param config - Optional message override.
|
|
904
832
|
* @returns void
|
|
@@ -916,55 +844,6 @@ function notEmpty(path, config) {
|
|
|
916
844
|
: null;
|
|
917
845
|
});
|
|
918
846
|
}
|
|
919
|
-
/**
|
|
920
|
-
* Requires the value to be both present and made of something: the two rules a mandatory text
|
|
921
|
-
* field almost always needs together, declared once.
|
|
922
|
-
*
|
|
923
|
-
* The signal-form counterpart of `RequiredNotEmptyValidatorDirective`. It raises the errors the
|
|
924
|
-
* two rules raise on their own rather than a kind of its own — `required` when nothing was
|
|
925
|
-
* entered, `notEmpty` when a value is there but blank — so the message stays as precise as it was
|
|
926
|
-
* and nothing downstream needs to learn a new kind.
|
|
927
|
-
*
|
|
928
|
-
* The presence half is DELEGATED to Angular's own `required()` and is not reimplemented here.
|
|
929
|
-
* That call does more than validate: it writes the `REQUIRED` metadata on the field, and that
|
|
930
|
-
* metadata is the only thing the Material compatibility layer looks at when it answers
|
|
931
|
-
* `hasValidator(Validators.required)` through `field().required()`. A plain `validate()` would
|
|
932
|
-
* reject the empty value just the same and silently drop the asterisk from the label.
|
|
933
|
-
*
|
|
934
|
-
* The empty array is the one case handled here rather than there: Angular's emptiness check is
|
|
935
|
-
* `value === '' || value === false || value == null`, so an empty array walks straight past
|
|
936
|
-
* `required()`. It is reported with the `required` kind all the same, because for a multi-value
|
|
937
|
-
* field "nothing selected" is exactly what the user needs to be told.
|
|
938
|
-
*
|
|
939
|
-
* @param path - Path of the field to validate.
|
|
940
|
-
* @param config - Optional message override, applied to whichever of the two errors is raised,
|
|
941
|
-
* and `when` condition, honoured by both halves of the rule.
|
|
942
|
-
* @returns void
|
|
943
|
-
* @example
|
|
944
|
-
* const f = form(this.model, p => { requiredNotEmpty(p.city); });
|
|
945
|
-
*/
|
|
946
|
-
function requiredNotEmpty(path, config) {
|
|
947
|
-
required(path, {
|
|
948
|
-
message: config?.message ?? ARS_VALIDATOR_MESSAGES['required'],
|
|
949
|
-
when: config?.when,
|
|
950
|
-
});
|
|
951
|
-
validate(path, ctx => {
|
|
952
|
-
if (config?.when && !config.when(ctx))
|
|
953
|
-
return null;
|
|
954
|
-
const input = ctx.value();
|
|
955
|
-
// The empty array, which `required()` above does not see.
|
|
956
|
-
if (Array.isArray(input) && input.length === 0) {
|
|
957
|
-
return { kind: 'required', message: config?.message ?? ARS_VALIDATOR_MESSAGES['required'] };
|
|
958
|
-
}
|
|
959
|
-
// Nullish and the empty string have already been reported by `required()`: saying it twice
|
|
960
|
-
// would put two errors on one empty field, which is what this rule exists to avoid.
|
|
961
|
-
if (isMissingValue(input))
|
|
962
|
-
return null;
|
|
963
|
-
return isBlankValue(input)
|
|
964
|
-
? { kind: 'notEmpty', message: config?.message ?? ARS_VALIDATOR_MESSAGES['notEmpty'] }
|
|
965
|
-
: null;
|
|
966
|
-
});
|
|
967
|
-
}
|
|
968
847
|
/**
|
|
969
848
|
* Requires the value to differ from the value of another field of the same form.
|
|
970
849
|
*
|
|
@@ -1411,5 +1290,5 @@ class SignalsUtils {
|
|
|
1411
1290
|
* Generated bundle index. Do not edit.
|
|
1412
1291
|
*/
|
|
1413
1292
|
|
|
1414
|
-
export { ARS_VALIDATOR_MESSAGES, EmailsValidatorDirective, EqualsValidatorDirective, FileSizeValidatorDirective, GuidValidatorDirective, MIN_VALID_YEAR, MaxTermsValidatorDirective, NotEmptyValidatorDirective, NotEqualValidatorDirective, NotFutureValidatorDirective, PasswordValidatorDirective,
|
|
1293
|
+
export { ARS_VALIDATOR_MESSAGES, EmailsValidatorDirective, EqualsValidatorDirective, FileSizeValidatorDirective, GuidValidatorDirective, MIN_VALID_YEAR, MaxTermsValidatorDirective, NotEmptyValidatorDirective, NotEqualValidatorDirective, NotFutureValidatorDirective, PasswordValidatorDirective, SignalsUtils, SqlDateValidatorDirective, TimeValidatorDirective, UrlValidatorDirective, ValidIfDirective, ValidatorDirective, date, dateRange, emails, equals, fileSize, guid, maxTerms, notEmpty, notEqual, notFuture, otp, password, sqlDate, time, url, validIf };
|
|
1415
1294
|
//# sourceMappingURL=arsedizioni-ars-utils-core.validators.mjs.map
|