@stemy/ngx-dynamic-form 19.9.2 → 19.9.3

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.
@@ -151,11 +151,10 @@ function convertToDateFormat(value, format) {
151
151
  return value;
152
152
  value = ObjectUtils.isDate(value) ? value : new Date(value);
153
153
  const date = isNaN(value) ? new Date() : value;
154
+ const target = new Date(date.getTime() - date.getTimezoneOffset() * 60000).toISOString();
154
155
  return format === "datetime-local" || format === "date-time"
155
- ? new Date(date.getTime() - date.getTimezoneOffset() * 60000)
156
- .toISOString()
157
- .slice(0, 16)
158
- : date.toISOString().slice(0, 10);
156
+ ? target.slice(0, 16)
157
+ : target.slice(0, 10);
159
158
  }
160
159
  /**
161
160
  * Convert value to date object with format (date, date-time)
@@ -317,9 +316,9 @@ function withName(fn, name) {
317
316
  return mainFn;
318
317
  }
319
318
  function validateEach(each, cb, name) {
320
- return withName((control) => {
319
+ return withName((control, field) => {
321
320
  const value = control.value;
322
- return each ? Array.isArray(value) && value.every(cb) : cb(value);
321
+ return each ? Array.isArray(value) && value.every(v => cb(v, field)) : cb(value, field);
323
322
  }, name);
324
323
  }
325
324
  function addFieldValidators(field, validators) {
@@ -346,7 +345,7 @@ function addFieldValidators(field, validators) {
346
345
  }
347
346
  function removeFieldValidators(field, ...names) {
348
347
  const validators = Object.assign({}, field.validators || {});
349
- const validation = field.validation || {};
348
+ const validation = Object.assign({}, field.validation || {});
350
349
  const messages = Object.assign({}, validation.messages || {});
351
350
  names.forEach(name => {
352
351
  delete validators[name];
@@ -413,8 +412,11 @@ function minLengthValidation(minLength, each) {
413
412
  function maxLengthValidation(maxLength, each) {
414
413
  return validateEach(each, v => typeof v == "string" && v.length <= maxLength, "maxLength");
415
414
  }
416
- function minValueValidation(min, each) {
417
- return validateEach(each, v => {
415
+ function minValueValidation(each) {
416
+ return validateEach(each, (v, f) => {
417
+ const type = f.props.type || "number";
418
+ const min = type.includes("date")
419
+ ? convertToDate(f.props.min, type) : Number(f.props.min ?? 0);
418
420
  if (min instanceof Date) {
419
421
  const date = new Date(v);
420
422
  return isNaN(date) || date >= min;
@@ -422,8 +424,11 @@ function minValueValidation(min, each) {
422
424
  return v == null || v >= min;
423
425
  }, "minValue");
424
426
  }
425
- function maxValueValidation(max, each) {
426
- return validateEach(each, v => {
427
+ function maxValueValidation(each) {
428
+ return validateEach(each, (v, f) => {
429
+ const type = f.props.type || "number";
430
+ const max = type.includes("date")
431
+ ? convertToDate(f.props.max, type) : Number(f.props.max ?? 0);
427
432
  if (max instanceof Date) {
428
433
  const date = new Date(v);
429
434
  return isNaN(date) || date <= max;
@@ -435,8 +440,7 @@ function setFieldMinDate(field, min) {
435
440
  setFieldDefault(field, min);
436
441
  setFieldProp(field, "min", min);
437
442
  setFieldValue(field, min);
438
- removeFieldValidators(field, "minValue");
439
- addFieldValidators(field, [minValueValidation(min)]);
443
+ addFieldValidators(field, [minValueValidation(field.type === "array")]);
440
444
  }
441
445
 
442
446
  class ModelUtils {
@@ -1438,10 +1442,10 @@ class DynamicFormSchemaService {
1438
1442
  validators.itemsMaxLength = maxLengthValidation(items.maxLength, true);
1439
1443
  }
1440
1444
  if (!isNaN(items.minimum)) {
1441
- validators.itemsMinValue = minValueValidation(items.minimum, true);
1445
+ validators.itemsMinValue = minValueValidation(true);
1442
1446
  }
1443
1447
  if (!isNaN(items.maximum)) {
1444
- validators.itemsMaxValue = maxValueValidation(items.maximum, true);
1448
+ validators.itemsMaxValue = maxValueValidation(true);
1445
1449
  }
1446
1450
  }
1447
1451
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.19", ngImport: i0, type: DynamicFormSchemaService, deps: [{ token: i2.OpenApiService }, { token: i0.Injector }, { token: DynamicFormBuilderService }], target: i0.ɵɵFactoryTarget.Injectable });