osl-base-extended 15.5.1 → 15.6.1
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.
|
@@ -489,9 +489,20 @@ class baseComponent {
|
|
|
489
489
|
continue;
|
|
490
490
|
const elem = col.formElem;
|
|
491
491
|
const isRequired = elem.required || elem.requiredIf?.(row);
|
|
492
|
+
const value = row[col.key];
|
|
493
|
+
if (elem.elementType === 'chips-input') {
|
|
494
|
+
const chips = this._chipValues(value);
|
|
495
|
+
const typeError = this._chipsTypeError(elem.inputType, chips);
|
|
496
|
+
if (isRequired && chips.length === 0) {
|
|
497
|
+
errors.push(`Row ${rowNum}, ${col.label ?? col.displayName} is required`);
|
|
498
|
+
}
|
|
499
|
+
else if (typeError) {
|
|
500
|
+
errors.push(`Row ${rowNum}, ${col.label ?? col.displayName} ${typeError}`);
|
|
501
|
+
}
|
|
502
|
+
continue;
|
|
503
|
+
}
|
|
492
504
|
if (!isRequired)
|
|
493
505
|
continue;
|
|
494
|
-
const value = row[col.key];
|
|
495
506
|
const isEmpty = value === null || value === undefined || value === ''
|
|
496
507
|
|| (Array.isArray(value) && value.length === 0);
|
|
497
508
|
if (isEmpty) {
|
|
@@ -518,11 +529,18 @@ class baseComponent {
|
|
|
518
529
|
const isRequired = el.required || el.requiredIf?.(model);
|
|
519
530
|
const value = model[el.key];
|
|
520
531
|
const isEmpty = value === null || value === undefined || value === ''
|
|
521
|
-
|| (Array.isArray(value) && value.length === 0)
|
|
532
|
+
|| (Array.isArray(value) && value.length === 0)
|
|
533
|
+
|| (el.elementType === 'chips-input' && this._chipValues(value).length === 0);
|
|
522
534
|
if (isRequired && isEmpty) {
|
|
523
535
|
errors.push(`${el.label} is required`);
|
|
524
536
|
continue;
|
|
525
537
|
}
|
|
538
|
+
if (el.elementType === 'chips-input') {
|
|
539
|
+
const typeError = this._chipsTypeError(el.inputType, this._chipValues(value));
|
|
540
|
+
if (typeError)
|
|
541
|
+
errors.push(`${el.label} ${typeError}`);
|
|
542
|
+
continue;
|
|
543
|
+
}
|
|
526
544
|
if (el.inputType === 'email' && !isEmpty) {
|
|
527
545
|
const emailRegex = /^(?!.*\.\.)(?!.*\.$)[A-Za-z0-9][A-Za-z0-9._%+-]{0,63}@[A-Za-z0-9-]+(?:\.[A-Za-z0-9-]+)*\.[A-Za-z]{2,}$/;
|
|
528
546
|
if (!emailRegex.test(value)) {
|
|
@@ -551,6 +569,28 @@ class baseComponent {
|
|
|
551
569
|
}
|
|
552
570
|
}
|
|
553
571
|
}
|
|
572
|
+
/** Normalises a chips-input value (string[] or comma separated string) to its chips. */
|
|
573
|
+
_chipValues(value) {
|
|
574
|
+
const list = Array.isArray(value) ? value : typeof value === 'string' ? value.split(',') : [];
|
|
575
|
+
return list.map(v => String(v ?? '').trim()).filter(v => !!v);
|
|
576
|
+
}
|
|
577
|
+
/** Returns the error suffix when any chip fails the element's inputType, otherwise null. */
|
|
578
|
+
_chipsTypeError(inputType, chips) {
|
|
579
|
+
switch (inputType) {
|
|
580
|
+
case 'email': {
|
|
581
|
+
const emailRegex = /^(?!.*\.\.)(?!.*\.$)[A-Za-z0-9][A-Za-z0-9._%+-]{0,63}@[A-Za-z0-9-]+(?:\.[A-Za-z0-9-]+)*\.[A-Za-z]{2,}$/;
|
|
582
|
+
return chips.every(c => emailRegex.test(c)) ? null : 'must contain only valid email addresses';
|
|
583
|
+
}
|
|
584
|
+
case 'number':
|
|
585
|
+
return chips.every(c => /^-?\d+(\.\d+)?$/.test(c)) ? null : 'must contain only valid numbers';
|
|
586
|
+
case 'int':
|
|
587
|
+
return chips.every(c => /^-?\d+$/.test(c)) ? null : 'must contain only whole numbers';
|
|
588
|
+
case 'url':
|
|
589
|
+
return chips.every(c => URL.canParse(c)) ? null : 'must contain only valid URLs';
|
|
590
|
+
default:
|
|
591
|
+
return null;
|
|
592
|
+
}
|
|
593
|
+
}
|
|
554
594
|
_formatDate(dateStr) {
|
|
555
595
|
const d = new Date(dateStr + 'T00:00:00');
|
|
556
596
|
if (isNaN(d.getTime()))
|
|
@@ -3485,7 +3525,8 @@ class OslChipsInput {
|
|
|
3485
3525
|
isValidValue(value) {
|
|
3486
3526
|
switch (this.inputType) {
|
|
3487
3527
|
case 'email':
|
|
3488
|
-
|
|
3528
|
+
// Same pattern as baseComponent's save-time validation, so an accepted chip never fails on save.
|
|
3529
|
+
return /^(?!.*\.\.)(?!.*\.$)[A-Za-z0-9][A-Za-z0-9._%+-]{0,63}@[A-Za-z0-9-]+(?:\.[A-Za-z0-9-]+)*\.[A-Za-z]{2,}$/.test(value);
|
|
3489
3530
|
case 'number':
|
|
3490
3531
|
return /^-?\d+(\.\d+)?$/.test(value);
|
|
3491
3532
|
case 'int':
|