ngx-dsxlibrary 1.21.36 → 1.21.37
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.
|
@@ -2871,6 +2871,55 @@ function dateRangeValidator(control) {
|
|
|
2871
2871
|
}
|
|
2872
2872
|
return null; // Si el control no contiene un array válido, no hay error
|
|
2873
2873
|
}
|
|
2874
|
+
/**
|
|
2875
|
+
* Validador a nivel de formulario que verifica que la fecha "hasta"
|
|
2876
|
+
* (toKey) sea mayor o igual que la fecha "desde" (fromKey),
|
|
2877
|
+
* comparando ambas como instancias de Date.
|
|
2878
|
+
*
|
|
2879
|
+
* Reglas:
|
|
2880
|
+
* - Si una o ambas fechas están vacías (null/undefined), no se genera error
|
|
2881
|
+
* y se delega la obligatoriedad a otros validadores como `required`.
|
|
2882
|
+
* - Si ambas fechas tienen valor, la fecha "hasta" debe ser >= fecha "desde"
|
|
2883
|
+
* según su valor numérico (`getTime()`).
|
|
2884
|
+
* - Si los valores no son fechas válidas, el comportamiento dependerá
|
|
2885
|
+
* de cómo los controles entreguen el valor (se recomienda usar Date).
|
|
2886
|
+
*
|
|
2887
|
+
* @param fromKey Nombre del control que representa la fecha inicial.
|
|
2888
|
+
* @param toKey Nombre del control que representa la fecha final.
|
|
2889
|
+
* @returns Un ValidatorFn que devuelve `null` si el rango es válido o está
|
|
2890
|
+
* incompleto; y un objeto con la clave `invalidDateRange` si el
|
|
2891
|
+
* rango es inválido.
|
|
2892
|
+
*/
|
|
2893
|
+
function dateRangeValidatorFromTo(fromKey, toKey) {
|
|
2894
|
+
return (group) => {
|
|
2895
|
+
const fromControl = group.get(fromKey);
|
|
2896
|
+
const toControl = group.get(toKey);
|
|
2897
|
+
const from = fromControl?.value;
|
|
2898
|
+
const to = toControl?.value;
|
|
2899
|
+
if (!from || !to)
|
|
2900
|
+
return null;
|
|
2901
|
+
// Rango válido: limpiar error en el control "hasta" si existe
|
|
2902
|
+
if (to.getTime() >= from.getTime()) {
|
|
2903
|
+
if (toControl && toControl.errors?.['invalidDateRange']) {
|
|
2904
|
+
const { invalidDateRange, ...rest } = toControl.errors;
|
|
2905
|
+
toControl.setErrors(Object.keys(rest).length ? rest : null);
|
|
2906
|
+
}
|
|
2907
|
+
return null;
|
|
2908
|
+
}
|
|
2909
|
+
// Rango inválido: asignar error tanto al grupo como al control "hasta"
|
|
2910
|
+
const error = {
|
|
2911
|
+
invalidDateRange: {
|
|
2912
|
+
message: 'La fecha final debe ser mayor o igual que la fecha inicial.',
|
|
2913
|
+
requiredLength: 2,
|
|
2914
|
+
},
|
|
2915
|
+
};
|
|
2916
|
+
if (toControl) {
|
|
2917
|
+
const currentErrors = toControl.errors || {};
|
|
2918
|
+
toControl.setErrors({ ...currentErrors, ...error });
|
|
2919
|
+
}
|
|
2920
|
+
return error;
|
|
2921
|
+
};
|
|
2922
|
+
}
|
|
2874
2923
|
/**
|
|
2875
2924
|
* Valida que una fecha única esté dentro de un rango mínimo y máximo.
|
|
2876
2925
|
* Las fechas deben utilizar la función de convertirFechaISOString para asegurar el formato correcto y que funcione con el componente primeNg.
|
|
@@ -3077,5 +3126,5 @@ function CUICorrecto(cui) {
|
|
|
3077
3126
|
* Generated bundle index. Do not edit.
|
|
3078
3127
|
*/
|
|
3079
3128
|
|
|
3080
|
-
export { AlertaService, AppMessageErrorComponent, AuthorizeService, CACHE_KEYS, CacheService, CssV2Component, DsxAddToolsModule, DteService, ENVIRONMENT, EndpointService, ErrorHandlerService, FileComponent, INITIAL_PARAMETERS, IconDsxComponent, JsonHighlightPipe, JsonValuesDebujComponent, KpicardComponent, LoadingComponent, LoadingLottieComponent, NavbarDsxComponent, OnlyRangoPatternDirective, ParameterValuesService, PrimeNgModule, SWEET_ALERT_THEMES, SecurityService, SelectAllOnFocusDirective, SpinnerLoadingService, TruncatePipe, UtilityAddService, atLeastOneFieldRequiredValidator, createInitialCache, createTypedCacheProvider, cuiValidator, dateMinMaxValidator, dateRangeValidator, httpAuthorizeInterceptor, nitValidator, provideEnvironment, validateEnvironmentConfig };
|
|
3129
|
+
export { AlertaService, AppMessageErrorComponent, AuthorizeService, CACHE_KEYS, CacheService, CssV2Component, DsxAddToolsModule, DteService, ENVIRONMENT, EndpointService, ErrorHandlerService, FileComponent, INITIAL_PARAMETERS, IconDsxComponent, JsonHighlightPipe, JsonValuesDebujComponent, KpicardComponent, LoadingComponent, LoadingLottieComponent, NavbarDsxComponent, OnlyRangoPatternDirective, ParameterValuesService, PrimeNgModule, SWEET_ALERT_THEMES, SecurityService, SelectAllOnFocusDirective, SpinnerLoadingService, TruncatePipe, UtilityAddService, atLeastOneFieldRequiredValidator, createInitialCache, createTypedCacheProvider, cuiValidator, dateMinMaxValidator, dateRangeValidator, dateRangeValidatorFromTo, httpAuthorizeInterceptor, nitValidator, provideEnvironment, validateEnvironmentConfig };
|
|
3081
3130
|
//# sourceMappingURL=ngx-dsxlibrary.mjs.map
|