@stemy/ngx-dynamic-form 19.9.6 → 19.9.8
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/stemy-ngx-dynamic-form.mjs +36 -32
- package/fesm2022/stemy-ngx-dynamic-form.mjs.map +1 -1
- package/ngx-dynamic-form/common-types.d.ts +1 -0
- package/ngx-dynamic-form/utils/misc.d.ts +4 -4
- package/ngx-dynamic-form/utils/validation.d.ts +4 -4
- package/package.json +1 -1
- package/public_api.d.ts +1 -1
|
@@ -175,33 +175,37 @@ function convertToNumber(value, defaultVal) {
|
|
|
175
175
|
const num = Number(value);
|
|
176
176
|
return isNaN(num) ? defaultVal ?? value : num;
|
|
177
177
|
}
|
|
178
|
-
function getFieldByPath(
|
|
179
|
-
|
|
178
|
+
function getFieldByPath(lookup, path) {
|
|
179
|
+
const field = ObjectUtils.isArray(lookup) ? null : lookup;
|
|
180
|
+
if (field?.path === path) {
|
|
180
181
|
return field;
|
|
181
182
|
}
|
|
182
|
-
|
|
183
|
+
const fields = ObjectUtils.isArray(lookup) ? lookup : field.fieldGroup;
|
|
184
|
+
if (!fields)
|
|
183
185
|
return null;
|
|
184
|
-
for (const sf of
|
|
186
|
+
for (const sf of fields) {
|
|
185
187
|
const found = getFieldByPath(sf, path);
|
|
186
188
|
if (found)
|
|
187
189
|
return found;
|
|
188
190
|
}
|
|
189
191
|
return null;
|
|
190
192
|
}
|
|
191
|
-
function getFieldsByPredicate(
|
|
192
|
-
|
|
193
|
+
function getFieldsByPredicate(lookup, cb) {
|
|
194
|
+
const field = ObjectUtils.isArray(lookup) ? null : lookup;
|
|
195
|
+
if (field && cb(field)) {
|
|
193
196
|
return [field];
|
|
194
197
|
}
|
|
195
|
-
if (!field.fieldGroup)
|
|
196
|
-
return [];
|
|
197
198
|
const results = [];
|
|
198
|
-
|
|
199
|
+
const fields = ObjectUtils.isArray(lookup) ? lookup : field.fieldGroup;
|
|
200
|
+
if (!fields)
|
|
201
|
+
return results;
|
|
202
|
+
for (const sf of fields) {
|
|
199
203
|
results.push(...getFieldsByPredicate(sf, cb));
|
|
200
204
|
}
|
|
201
205
|
return results;
|
|
202
206
|
}
|
|
203
|
-
function getFieldsByKey(
|
|
204
|
-
return getFieldsByPredicate(
|
|
207
|
+
function getFieldsByKey(lookup, key) {
|
|
208
|
+
return getFieldsByPredicate(lookup, f => f.key === key);
|
|
205
209
|
}
|
|
206
210
|
async function getSelectOptions(fieldOrOpts) {
|
|
207
211
|
const options = fieldOrOpts.props?.options || fieldOrOpts;
|
|
@@ -315,10 +319,10 @@ function withName(fn, name) {
|
|
|
315
319
|
mainFn.validatorName = name;
|
|
316
320
|
return mainFn;
|
|
317
321
|
}
|
|
318
|
-
function validateEach(
|
|
322
|
+
function validateEach(cb, name) {
|
|
319
323
|
return withName((control, field) => {
|
|
320
324
|
const value = control.value;
|
|
321
|
-
return
|
|
325
|
+
return field.type === "array" ? Array.isArray(value) && value.every(v => cb(v, field)) : cb(value, field);
|
|
322
326
|
}, name);
|
|
323
327
|
}
|
|
324
328
|
function addFieldValidators(field, validators) {
|
|
@@ -410,14 +414,14 @@ function arrayLengthValidation(min = 1, max = Number.MAX_SAFE_INTEGER) {
|
|
|
410
414
|
return !Array.isArray(value) || (min <= value.length && value.length <= max);
|
|
411
415
|
}, "arrayLength");
|
|
412
416
|
}
|
|
413
|
-
function minLengthValidation(minLength
|
|
414
|
-
return validateEach(
|
|
417
|
+
function minLengthValidation(minLength) {
|
|
418
|
+
return validateEach(v => typeof v == "string" && v.length >= minLength, "minLength");
|
|
415
419
|
}
|
|
416
|
-
function maxLengthValidation(maxLength
|
|
417
|
-
return validateEach(
|
|
420
|
+
function maxLengthValidation(maxLength) {
|
|
421
|
+
return validateEach(v => typeof v == "string" && v.length <= maxLength, "maxLength");
|
|
418
422
|
}
|
|
419
|
-
function minValueValidation(
|
|
420
|
-
return validateEach(
|
|
423
|
+
function minValueValidation() {
|
|
424
|
+
return validateEach((v, f) => {
|
|
421
425
|
const type = f.props.type || "number";
|
|
422
426
|
const min = type.includes("date")
|
|
423
427
|
? convertToDate(f.props.min, type) : Number(f.props.min ?? 0);
|
|
@@ -428,8 +432,8 @@ function minValueValidation(each) {
|
|
|
428
432
|
return v == null || v >= min;
|
|
429
433
|
}, "minValue");
|
|
430
434
|
}
|
|
431
|
-
function maxValueValidation(
|
|
432
|
-
return validateEach(
|
|
435
|
+
function maxValueValidation() {
|
|
436
|
+
return validateEach((v, f) => {
|
|
433
437
|
const type = f.props.type || "number";
|
|
434
438
|
const max = type.includes("date")
|
|
435
439
|
? convertToDate(f.props.max, type) : Number(f.props.max ?? 0);
|
|
@@ -444,7 +448,7 @@ function setFieldMinDate(field, min) {
|
|
|
444
448
|
setFieldDefault(field, min);
|
|
445
449
|
setFieldProp(field, "min", min);
|
|
446
450
|
setFieldValue(field, min);
|
|
447
|
-
addFieldValidators(field, [minValueValidation(
|
|
451
|
+
addFieldValidators(field, [minValueValidation()]);
|
|
448
452
|
}
|
|
449
453
|
|
|
450
454
|
class ModelUtils {
|
|
@@ -1244,8 +1248,8 @@ class DynamicFormSchemaService {
|
|
|
1244
1248
|
autocomplete: property.autocomplete,
|
|
1245
1249
|
pattern: property.pattern,
|
|
1246
1250
|
step: isNaN(sub.step) ? property.step : sub.step,
|
|
1247
|
-
min: sub.minimum,
|
|
1248
|
-
max: sub.maximum,
|
|
1251
|
+
min: sub.minimum ?? sub.min,
|
|
1252
|
+
max: sub.maximum ?? sub.max,
|
|
1249
1253
|
minLength: sub.minLength,
|
|
1250
1254
|
maxLength: sub.maxLength,
|
|
1251
1255
|
placeholder: property.placeholder,
|
|
@@ -1289,8 +1293,8 @@ class DynamicFormSchemaService {
|
|
|
1289
1293
|
return this.builder.createFormInput(property.id, {
|
|
1290
1294
|
...this.getFormFieldData(property, options),
|
|
1291
1295
|
type,
|
|
1292
|
-
min: convertToDateFormat(property.min, property.format),
|
|
1293
|
-
max: convertToDateFormat(property.max, property.format),
|
|
1296
|
+
min: convertToDateFormat(property.minimum ?? property.min, property.format),
|
|
1297
|
+
max: convertToDateFormat(property.maximum ?? property.max, property.format),
|
|
1294
1298
|
}, parent, options);
|
|
1295
1299
|
}
|
|
1296
1300
|
getFormSelectConfig($enum, property, options, parent) {
|
|
@@ -1428,10 +1432,10 @@ class DynamicFormSchemaService {
|
|
|
1428
1432
|
validators.maxLength = maxLengthValidation(property.maxLength);
|
|
1429
1433
|
}
|
|
1430
1434
|
if (!isNaN(property.minimum)) {
|
|
1431
|
-
validators.min = minValueValidation(
|
|
1435
|
+
validators.min = minValueValidation();
|
|
1432
1436
|
}
|
|
1433
1437
|
if (!isNaN(property.maximum)) {
|
|
1434
|
-
validators.max = maxValueValidation(
|
|
1438
|
+
validators.max = maxValueValidation();
|
|
1435
1439
|
}
|
|
1436
1440
|
// if (isString(property.pattern) && property.pattern.length) {
|
|
1437
1441
|
// validators.pattern = property.pattern;
|
|
@@ -1446,16 +1450,16 @@ class DynamicFormSchemaService {
|
|
|
1446
1450
|
if (!items)
|
|
1447
1451
|
return;
|
|
1448
1452
|
if (!isNaN(items.minLength)) {
|
|
1449
|
-
validators.itemsMinLength = minLengthValidation(items.minLength
|
|
1453
|
+
validators.itemsMinLength = minLengthValidation(items.minLength);
|
|
1450
1454
|
}
|
|
1451
1455
|
if (!isNaN(items.maxLength)) {
|
|
1452
|
-
validators.itemsMaxLength = maxLengthValidation(items.maxLength
|
|
1456
|
+
validators.itemsMaxLength = maxLengthValidation(items.maxLength);
|
|
1453
1457
|
}
|
|
1454
1458
|
if (!isNaN(items.minimum)) {
|
|
1455
|
-
validators.itemsMinValue = minValueValidation(
|
|
1459
|
+
validators.itemsMinValue = minValueValidation();
|
|
1456
1460
|
}
|
|
1457
1461
|
if (!isNaN(items.maximum)) {
|
|
1458
|
-
validators.itemsMaxValue = maxValueValidation(
|
|
1462
|
+
validators.itemsMaxValue = maxValueValidation();
|
|
1459
1463
|
}
|
|
1460
1464
|
}
|
|
1461
1465
|
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 });
|