@quadrel-enterprise-ui/framework 21.4.5 → 21.5.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.
@@ -13041,8 +13041,10 @@ class QdDatepickerComponent {
13041
13041
  timePicker;
13042
13042
  _disabledDatesValidator;
13043
13043
  _disabledTimesValidator;
13044
+ _dateTimeValidator;
13044
13045
  _boundDisabledDates;
13045
13046
  _boundDisabledTimes;
13047
+ _boundDateTimeValidation;
13046
13048
  _subs = new Subscription();
13047
13049
  _onChange = () => { };
13048
13050
  _onTouched = () => { };
@@ -13064,6 +13066,7 @@ class QdDatepickerComponent {
13064
13066
  ngDoCheck() {
13065
13067
  this.rebindDisabledDatesValidatorIfChanged();
13066
13068
  this.rebindDisabledTimesValidatorIfChanged();
13069
+ this.rebindDateTimeValidatorIfChanged();
13067
13070
  }
13068
13071
  ngOnDestroy() {
13069
13072
  this._subs.unsubscribe();
@@ -13272,6 +13275,43 @@ class QdDatepickerComponent {
13272
13275
  this._boundDisabledTimes = current;
13273
13276
  this.validateDisabledTimes();
13274
13277
  }
13278
+ rebindDateTimeValidatorIfChanged() {
13279
+ const current = this.dateTimeValidationSignature;
13280
+ if (current === this._boundDateTimeValidation)
13281
+ return;
13282
+ if (!this.control)
13283
+ return;
13284
+ this._boundDateTimeValidation = current;
13285
+ this.validateDateTime();
13286
+ }
13287
+ /**
13288
+ * Identifies the date-time error message the current config asks for. `undefined` means the
13289
+ * picker is date-only and the plain `date` message applies.
13290
+ */
13291
+ get dateTimeValidationSignature() {
13292
+ if (!this.config?.timePicker)
13293
+ return undefined;
13294
+ return this.config.enableSeconds ? 'withSeconds' : 'withoutSeconds';
13295
+ }
13296
+ /**
13297
+ * Makes the invalid-input message name the date *and time* format the input expects. The
13298
+ * validator reports under the same `date` error key as `QdValidators.date()`, so it replaces
13299
+ * the date-only message instead of adding a second one.
13300
+ */
13301
+ validateDateTime() {
13302
+ if (!this.control)
13303
+ return;
13304
+ if (this._dateTimeValidator) {
13305
+ this.control.removeValidators(this._dateTimeValidator);
13306
+ this._dateTimeValidator = undefined;
13307
+ this.control.updateValueAndValidity();
13308
+ }
13309
+ if (!this.config?.timePicker)
13310
+ return;
13311
+ this._dateTimeValidator = QdValidators.dateTime(!!this.config.enableSeconds);
13312
+ this.control.addValidators(this._dateTimeValidator);
13313
+ this.control.updateValueAndValidity();
13314
+ }
13275
13315
  validateDisabledDates() {
13276
13316
  if (!this.control)
13277
13317
  return;
@@ -16211,6 +16251,40 @@ class QdValidators {
16211
16251
  return this.isValidDate(value) ? null : formattedErrorKey;
16212
16252
  };
16213
16253
  }
16254
+ /**
16255
+ * Validates that the value is a real, parseable `Date` object and names the **date and time**
16256
+ * format in the error message.
16257
+ *
16258
+ * Behaves exactly like {@link QdValidators.date}, but the message points at the format a
16259
+ * date-time input expects (`DD.MM.YYYY HH:mm`, or `DD.MM.YYYY HH:mm:ss` when seconds are
16260
+ * enabled) instead of the date-only one. The error is reported under the same `date` key as
16261
+ * {@link QdValidators.date}, so adding it to a control that already carries `date()` replaces
16262
+ * that message rather than showing a second one.
16263
+ *
16264
+ * `qd-datepicker` adds this validator on its own whenever a `timePicker` is configured — reach
16265
+ * for it directly only when validating a date-time value outside of the component.
16266
+ *
16267
+ * @param enableSeconds - Whether the input accepts seconds; mirrors the datepicker config of the same name.
16268
+ * @param errorKey - Translation key returned when the value is not a valid date.
16269
+ *
16270
+ * #### **Usage**
16271
+ * ```ts
16272
+ * new QdFormControl(null, QdValidators.dateTime());
16273
+ * new QdFormControl(new Date(), QdValidators.dateTime(true));
16274
+ * new QdFormControl(new Date(), QdValidators.dateTime(false, 'date-time-error'));
16275
+ * ```
16276
+ */
16277
+ static dateTime(enableSeconds = false, errorKey) {
16278
+ const key = errorKey ?? (enableSeconds ? 'i18n.qd.form.error.dateTimeWithSeconds' : 'i18n.qd.form.error.dateTime');
16279
+ const format = enableSeconds ? 'DD.MM.YYYY HH:mm:ss' : 'DD.MM.YYYY HH:mm';
16280
+ return ({ value }) => {
16281
+ if (!value)
16282
+ return null;
16283
+ const localizedFormat = moment().format(format);
16284
+ const formattedErrorKey = { date: { key, params: { format: localizedFormat } } };
16285
+ return this.isValidDate(value) ? null : formattedErrorKey;
16286
+ };
16287
+ }
16214
16288
  /**
16215
16289
  * Validates that a date does not fall inside any of the given disabled ranges.
16216
16290
  *
@@ -16282,19 +16356,60 @@ class QdValidators {
16282
16356
  * ```
16283
16357
  */
16284
16358
  static dateRange(partnerControlName, position, errorKey = 'i18n.qd.form.error.dateRange') {
16285
- const validFn = (control) => {
16286
- const ownValue = control.value;
16287
- const partnerValue = control.parent?.get(partnerControlName)?.value;
16288
- if (!this.isValidDate(ownValue) || !this.isValidDate(partnerValue))
16289
- return null;
16290
- const own = moment(ownValue);
16291
- const partner = moment(partnerValue);
16292
- const isInvalid = position === 'start' ? own.isAfter(partner, 'day') : own.isBefore(partner, 'day');
16293
- return isInvalid ? { dateRange: errorKey } : null;
16294
- };
16359
+ const validFn = (control) => this.isRangeOrderViolated(control, partnerControlName, position, 'day') ? { dateRange: errorKey } : null;
16295
16360
  validFn.qdRevalidates = partnerControlName;
16296
16361
  return validFn;
16297
16362
  }
16363
+ /**
16364
+ * Validates that a date **and time** stays on the correct side of a sibling "range partner"
16365
+ * control.
16366
+ *
16367
+ * The date-time counterpart of {@link QdValidators.dateRange}: identical wiring, but the
16368
+ * comparison includes the time of day instead of stopping at the day. Use it for a from/to
16369
+ * pair of datepickers that have a `timePicker` configured — `dateRange` accepts `10:00` to
16370
+ * `08:00` on the same day, this one rejects it.
16371
+ *
16372
+ * Put it on both ends of the pair, each pointing at the other. A `'start'` control is invalid
16373
+ * when its value lies after the partner; an `'end'` control is invalid when its value lies
16374
+ * before the partner. Equal instants are valid, so a zero-length range passes. The comparison
16375
+ * is exact, which fits both picker precisions on its own: without seconds the entered values
16376
+ * carry `:00` seconds, with `enableSeconds` they carry the entered ones.
16377
+ *
16378
+ * Everything else behaves like {@link QdValidators.dateRange}: the partner value is read live
16379
+ * on every run, empty or invalid own/partner values and a missing partner control all pass,
16380
+ * and `qdRevalidates` keeps both ends in sync inside a `QdFormGroup` — see there for the cases
16381
+ * that still need a manual `updateValueAndValidity`.
16382
+ *
16383
+ * @param partnerControlName - Name of the sibling control holding the other end of the range.
16384
+ * @param position - `'start'` for the from-control, `'end'` for the to-control.
16385
+ * @param errorKey - Translation key returned when the order is violated.
16386
+ *
16387
+ * #### **Usage**
16388
+ * ```ts
16389
+ * new QdFormGroup({
16390
+ * from: new QdFormControl(null, QdValidators.dateTimeRange('to', 'start')),
16391
+ * to: new QdFormControl(null, QdValidators.dateTimeRange('from', 'end'))
16392
+ * });
16393
+ * ```
16394
+ */
16395
+ static dateTimeRange(partnerControlName, position, errorKey = 'i18n.qd.form.error.dateTimeRange') {
16396
+ const validFn = (control) => this.isRangeOrderViolated(control, partnerControlName, position) ? { dateTimeRange: errorKey } : null;
16397
+ validFn.qdRevalidates = partnerControlName;
16398
+ return validFn;
16399
+ }
16400
+ /**
16401
+ * Compares a control against its range partner. Without a `granularity` the comparison is
16402
+ * exact, which is what a date *and time* range needs; `'day'` ignores the time of day.
16403
+ */
16404
+ static isRangeOrderViolated(control, partnerControlName, position, granularity) {
16405
+ const ownValue = control.value;
16406
+ const partnerValue = control.parent?.get(partnerControlName)?.value;
16407
+ if (!this.isValidDate(ownValue) || !this.isValidDate(partnerValue))
16408
+ return false;
16409
+ const own = moment(ownValue);
16410
+ const partner = moment(partnerValue);
16411
+ return position === 'start' ? own.isAfter(partner, granularity) : own.isBefore(partner, granularity);
16412
+ }
16298
16413
  static isValidDate(value) {
16299
16414
  return value instanceof Date && !isNaN(value.getTime());
16300
16415
  }