@aurodesignsystem/auro-formkit 3.1.0-beta.1 → 3.2.0-beta.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.
- package/CHANGELOG.md +19 -1
- package/components/checkbox/README.md +1 -1
- package/components/checkbox/demo/api.min.js +468 -25
- package/components/checkbox/demo/index.min.js +468 -25
- package/components/checkbox/demo/readme.md +1 -1
- package/components/checkbox/dist/index.js +468 -25
- package/components/checkbox/dist/registered.js +468 -25
- package/components/combobox/README.md +1 -1
- package/components/combobox/demo/api.min.js +1125 -74
- package/components/combobox/demo/index.min.js +1125 -74
- package/components/combobox/demo/readme.md +1 -1
- package/components/combobox/dist/auro-combobox.d.ts +30 -0
- package/components/combobox/dist/index.js +1125 -74
- package/components/combobox/dist/registered.js +1125 -74
- package/components/counter/README.md +1 -1
- package/components/counter/demo/api.min.js +570 -45
- package/components/counter/demo/index.min.js +570 -45
- package/components/counter/demo/readme.md +1 -1
- package/components/counter/dist/index.js +570 -45
- package/components/counter/dist/registered.js +570 -45
- package/components/datepicker/README.md +1 -1
- package/components/datepicker/demo/api.min.js +1073 -70
- package/components/datepicker/demo/index.min.js +1073 -70
- package/components/datepicker/demo/readme.md +1 -1
- package/components/datepicker/dist/index.js +1073 -70
- package/components/datepicker/dist/registered.js +1073 -70
- package/components/dropdown/README.md +1 -1
- package/components/dropdown/demo/api.md +8 -5
- package/components/dropdown/demo/api.min.js +104 -22
- package/components/dropdown/demo/index.min.js +104 -22
- package/components/dropdown/demo/readme.md +1 -1
- package/components/dropdown/dist/auro-dropdown.d.ts +29 -0
- package/components/dropdown/dist/index.js +104 -22
- package/components/dropdown/dist/registered.js +104 -22
- package/components/form/README.md +1 -1
- package/components/form/demo/readme.md +1 -1
- package/components/input/README.md +1 -1
- package/components/input/demo/api.md +4 -1
- package/components/input/demo/api.min.js +503 -25
- package/components/input/demo/index.min.js +503 -25
- package/components/input/demo/readme.md +1 -1
- package/components/input/dist/base-input.d.ts +24 -0
- package/components/input/dist/index.js +503 -25
- package/components/input/dist/registered.js +503 -25
- package/components/menu/README.md +1 -1
- package/components/menu/demo/readme.md +1 -1
- package/components/radio/README.md +1 -1
- package/components/radio/demo/api.min.js +468 -25
- package/components/radio/demo/index.min.js +468 -25
- package/components/radio/demo/readme.md +1 -1
- package/components/radio/dist/index.js +468 -25
- package/components/radio/dist/registered.js +468 -25
- package/components/select/README.md +1 -1
- package/components/select/demo/api.min.js +570 -45
- package/components/select/demo/index.min.js +570 -45
- package/components/select/demo/readme.md +1 -1
- package/components/select/dist/index.js +570 -45
- package/components/select/dist/registered.js +570 -45
- package/package.json +2 -2
|
@@ -339,11 +339,420 @@ class AuroCheckbox extends r {
|
|
|
339
339
|
*/
|
|
340
340
|
const a=Symbol.for(""),o=t=>{if(t?.r===a)return t?._$litStatic$},s=t=>({_$litStatic$:t,r:a}),i=(t,...r)=>({_$litStatic$:r.reduce(((r,e,a)=>r+(t=>{if(void 0!==t._$litStatic$)return t._$litStatic$;throw Error(`Value passed to 'literal' function must be a 'literal' result: ${t}. Use 'unsafeStatic' to pass non-literal values, but\n take care to ensure page security.`)})(e)+t[a+1]),t[0]),r:a}),l=new Map,n=t=>(r,...e)=>{const a=e.length;let s,i;const n=[],u=[];let c,$=0,f=false;for(;$<a;){for(c=r[$];$<a&&void 0!==(i=e[$],s=o(i));)c+=s+r[++$],f=true;$!==a&&u.push(i),n.push(c),$++;}if($===a&&n.push(r[a]),f){const t=n.join("$$lit$$");void 0===(r=l.get(t))&&(n.raw=n,l.set(t,r=n)),e=u;}return t(r,...e)},u=n(x);
|
|
341
341
|
|
|
342
|
+
class DateFormatter {
|
|
343
|
+
|
|
344
|
+
constructor() {
|
|
345
|
+
|
|
346
|
+
/**
|
|
347
|
+
* @description Parses a date string into its components.
|
|
348
|
+
* @param {string} dateStr - Date string to parse.
|
|
349
|
+
* @param {string} format - Date format to parse.
|
|
350
|
+
* @returns {Object<key["month" | "day" | "year"]: number>|undefined}
|
|
351
|
+
*/
|
|
352
|
+
this.parseDate = (dateStr, format = 'mm/dd/yyyy') => {
|
|
353
|
+
|
|
354
|
+
// Guard Clause: Date string is defined
|
|
355
|
+
if (!dateStr) {
|
|
356
|
+
return undefined;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
// Assume the separator is a "/" a defined in our code base
|
|
360
|
+
const separator = '/';
|
|
361
|
+
|
|
362
|
+
// Get the parts of the date and format
|
|
363
|
+
const valueParts = dateStr.split(separator);
|
|
364
|
+
const formatParts = format.split(separator);
|
|
365
|
+
|
|
366
|
+
// Check if the value and format have the correct number of parts
|
|
367
|
+
if (valueParts.length !== formatParts.length) {
|
|
368
|
+
throw new Error('AuroDatepickerUtilities | parseDate: Date string and format length do not match');
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
// Holds the result to be returned
|
|
372
|
+
const result = formatParts.reduce((acc, part, index) => {
|
|
373
|
+
const value = valueParts[index];
|
|
374
|
+
|
|
375
|
+
if ((/m/iu).test(part)) {
|
|
376
|
+
acc.month = value;
|
|
377
|
+
} else if ((/d/iu).test(part)) {
|
|
378
|
+
acc.day = value;
|
|
379
|
+
} else if ((/y/iu).test(part)) {
|
|
380
|
+
acc.year = value;
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
return acc;
|
|
384
|
+
}, {});
|
|
385
|
+
|
|
386
|
+
// If we found all the parts, return the result
|
|
387
|
+
if (result.month && result.year) {
|
|
388
|
+
return result;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
// Throw an error to let the dev know we were unable to parse the date string
|
|
392
|
+
throw new Error('AuroDatepickerUtilities | parseDate: Unable to parse date string');
|
|
393
|
+
};
|
|
394
|
+
|
|
395
|
+
/**
|
|
396
|
+
* Convert a date object to string format.
|
|
397
|
+
* @param {Object} date - Date to convert to string.
|
|
398
|
+
* @returns {Object} Returns the date as a string.
|
|
399
|
+
*/
|
|
400
|
+
this.getDateAsString = (date) => date.toLocaleDateString(undefined, {
|
|
401
|
+
year: "numeric",
|
|
402
|
+
month: "2-digit",
|
|
403
|
+
day: "2-digit",
|
|
404
|
+
});
|
|
405
|
+
|
|
406
|
+
/**
|
|
407
|
+
* Converts a date string to a North American date format.
|
|
408
|
+
* @param {String} dateStr - Date to validate.
|
|
409
|
+
* @param {String} format - Date format to validate against.
|
|
410
|
+
* @returns {Boolean}
|
|
411
|
+
*/
|
|
412
|
+
this.toNorthAmericanFormat = (dateStr, format) => {
|
|
413
|
+
|
|
414
|
+
if (format === 'mm/dd/yyyy') {
|
|
415
|
+
return dateStr;
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
const parsedDate = this.parseDate(dateStr, format);
|
|
419
|
+
|
|
420
|
+
if (!parsedDate) {
|
|
421
|
+
throw new Error('AuroDatepickerUtilities | toNorthAmericanFormat: Unable to parse date string');
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
const { month, day, year } = parsedDate;
|
|
425
|
+
|
|
426
|
+
const dateParts = [];
|
|
427
|
+
if (month) {
|
|
428
|
+
dateParts.push(month);
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
if (day) {
|
|
432
|
+
dateParts.push(day);
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
if (year) {
|
|
436
|
+
dateParts.push(year);
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
return dateParts.join('/');
|
|
440
|
+
};
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
const dateFormatter = new DateFormatter();
|
|
444
|
+
|
|
445
|
+
// filepath: dateConstraints.mjs
|
|
446
|
+
const DATE_UTIL_CONSTRAINTS = {
|
|
447
|
+
maxDay: 31,
|
|
448
|
+
maxMonth: 12,
|
|
449
|
+
maxYear: 2400,
|
|
450
|
+
minDay: 1,
|
|
451
|
+
minMonth: 1,
|
|
452
|
+
minYear: 1900,
|
|
453
|
+
};
|
|
454
|
+
|
|
455
|
+
class AuroDateUtilitiesBase {
|
|
456
|
+
|
|
457
|
+
/**
|
|
458
|
+
* @description The maximum day value allowed by the various utilities in this class.
|
|
459
|
+
* @readonly
|
|
460
|
+
* @type {Number}
|
|
461
|
+
*/
|
|
462
|
+
get maxDay() {
|
|
463
|
+
return DATE_UTIL_CONSTRAINTS.maxDay;
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
/**
|
|
467
|
+
* @description The maximum month value allowed by the various utilities in this class.
|
|
468
|
+
* @readonly
|
|
469
|
+
* @type {Number}
|
|
470
|
+
*/
|
|
471
|
+
get maxMonth() {
|
|
472
|
+
return DATE_UTIL_CONSTRAINTS.maxMonth;
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
/**
|
|
476
|
+
* @description The maximum year value allowed by the various utilities in this class.
|
|
477
|
+
* @readonly
|
|
478
|
+
* @type {Number}
|
|
479
|
+
*/
|
|
480
|
+
get maxYear() {
|
|
481
|
+
return DATE_UTIL_CONSTRAINTS.maxYear;
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
/**
|
|
485
|
+
* @description The minimum day value allowed by the various utilities in this class.
|
|
486
|
+
* @readonly
|
|
487
|
+
* @type {Number}
|
|
488
|
+
*/
|
|
489
|
+
get minDay() {
|
|
490
|
+
return DATE_UTIL_CONSTRAINTS.minDay;
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
/**
|
|
494
|
+
* @description The minimum month value allowed by the various utilities in this class.
|
|
495
|
+
* @readonly
|
|
496
|
+
* @type {Number}
|
|
497
|
+
*/
|
|
498
|
+
get minMonth() {
|
|
499
|
+
return DATE_UTIL_CONSTRAINTS.minMonth;
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
/**
|
|
503
|
+
* @description The minimum year value allowed by the various utilities in this class.
|
|
504
|
+
* @readonly
|
|
505
|
+
* @type {Number}
|
|
506
|
+
*/
|
|
507
|
+
get minYear() {
|
|
508
|
+
return DATE_UTIL_CONSTRAINTS.minYear;
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
/* eslint-disable no-magic-numbers */
|
|
513
|
+
|
|
514
|
+
class AuroDateUtilities extends AuroDateUtilitiesBase {
|
|
515
|
+
|
|
516
|
+
/**
|
|
517
|
+
* Returns the current century.
|
|
518
|
+
* @returns {String} The current century.
|
|
519
|
+
*/
|
|
520
|
+
getCentury () {
|
|
521
|
+
return String(new Date().getFullYear()).slice(0, 2);
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
/**
|
|
525
|
+
* Returns a four digit year.
|
|
526
|
+
* @param {String} year - The year to convert to four digits.
|
|
527
|
+
* @returns {String} The four digit year.
|
|
528
|
+
*/
|
|
529
|
+
getFourDigitYear (year) {
|
|
530
|
+
|
|
531
|
+
const strYear = String(year).trim();
|
|
532
|
+
return strYear.length <= 2 ? this.getCentury() + strYear : strYear;
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
constructor() {
|
|
536
|
+
|
|
537
|
+
super();
|
|
538
|
+
|
|
539
|
+
/**
|
|
540
|
+
* Compares two dates to see if they match.
|
|
541
|
+
* @param {Object} date1 - First date to compare.
|
|
542
|
+
* @param {Object} date2 - Second date to compare.
|
|
543
|
+
* @returns {Boolean} Returns true if the dates match.
|
|
544
|
+
*/
|
|
545
|
+
this.datesMatch = (date1, date2) => new Date(date1).getTime() === new Date(date2).getTime();
|
|
546
|
+
|
|
547
|
+
/**
|
|
548
|
+
* Returns true if value passed in is a valid date.
|
|
549
|
+
* @param {String} date - Date to validate.
|
|
550
|
+
* @param {String} format - Date format to validate against.
|
|
551
|
+
* @returns {Boolean}
|
|
552
|
+
*/
|
|
553
|
+
this.validDateStr = (date, format) => {
|
|
554
|
+
|
|
555
|
+
// The length we expect the date string to be
|
|
556
|
+
const dateStrLength = format.length;
|
|
557
|
+
|
|
558
|
+
// Guard Clause: Date and format are defined
|
|
559
|
+
if (typeof date === "undefined" || typeof format === "undefined") {
|
|
560
|
+
throw new Error('AuroDatepickerUtilities | validateDateStr: Date and format are required');
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
// Guard Clause: Date should be of type string
|
|
564
|
+
if (typeof date !== "string") {
|
|
565
|
+
throw new Error('AuroDatepickerUtilities | validateDateStr: Date must be a string');
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
// Guard Clause: Format should be of type string
|
|
569
|
+
if (typeof format !== "string") {
|
|
570
|
+
throw new Error('AuroDatepickerUtilities | validateDateStr: Format must be a string');
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
// Guard Clause: Length is what we expect it to be
|
|
574
|
+
if (date.length !== dateStrLength) {
|
|
575
|
+
return false;
|
|
576
|
+
}
|
|
577
|
+
// Get a formatted date string and parse it
|
|
578
|
+
const dateParts = dateFormatter.parseDate(date, format);
|
|
579
|
+
|
|
580
|
+
// Guard Clause: Date parse succeeded
|
|
581
|
+
if (!dateParts) {
|
|
582
|
+
return false;
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
// Create the expected date string based on the date parts
|
|
586
|
+
const expectedDateStr = `${dateParts.month}/${dateParts.day || "01"}/${this.getFourDigitYear(dateParts.year)}`;
|
|
587
|
+
|
|
588
|
+
// Generate a date object that we will extract a string date from to compare to the passed in date string
|
|
589
|
+
const dateObj = new Date(this.getFourDigitYear(dateParts.year), dateParts.month - 1, dateParts.day || 1);
|
|
590
|
+
|
|
591
|
+
// Get the date string of the date object we created from the string date
|
|
592
|
+
const actualDateStr = dateFormatter.getDateAsString(dateObj);
|
|
593
|
+
|
|
594
|
+
// Guard Clause: Generated date matches date string input
|
|
595
|
+
if (expectedDateStr !== actualDateStr) {
|
|
596
|
+
return false;
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
// If we passed all other checks, we can assume the date is valid
|
|
600
|
+
return true;
|
|
601
|
+
};
|
|
602
|
+
|
|
603
|
+
/**
|
|
604
|
+
* Determines if a string date value matches the format provided.
|
|
605
|
+
* @param {string} value = The date string value.
|
|
606
|
+
* @param { string} format = The date format to match against.
|
|
607
|
+
* @returns {boolean}
|
|
608
|
+
*/
|
|
609
|
+
this.dateAndFormatMatch = (value, format) => {
|
|
610
|
+
|
|
611
|
+
// Ensure we have both values we need to do the comparison
|
|
612
|
+
if (!value || !format) {
|
|
613
|
+
throw new Error('AuroFormValidation | dateFormatMatch: value and format are required');
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
// If the lengths are different, they cannot match
|
|
617
|
+
if (value.length !== format.length) {
|
|
618
|
+
return false;
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
// Get the parts of the date
|
|
622
|
+
const dateParts = dateFormatter.parseDate(value, format);
|
|
623
|
+
|
|
624
|
+
// Validator for day
|
|
625
|
+
const dayValueIsValid = (day) => {
|
|
626
|
+
|
|
627
|
+
// Guard clause: if there is no day in the dateParts, we can ignore this check.
|
|
628
|
+
if (!dateParts.day) {
|
|
629
|
+
return true;
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
// Guard clause: ensure day exists.
|
|
633
|
+
if (!day) {
|
|
634
|
+
return false;
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
// Convert day to number
|
|
638
|
+
const numDay = Number.parseInt(day, 10);
|
|
639
|
+
|
|
640
|
+
// Guard clause: ensure day is a valid integer
|
|
641
|
+
if (Number.isNaN(numDay)) {
|
|
642
|
+
throw new Error('AuroDatepickerUtilities | dayValueIsValid: Unable to parse day value integer');
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
// Guard clause: ensure day is within the valid range
|
|
646
|
+
if (numDay < this.minDay || numDay > this.maxDay) {
|
|
647
|
+
return false;
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
// Default return
|
|
651
|
+
return true;
|
|
652
|
+
};
|
|
653
|
+
|
|
654
|
+
// Validator for month
|
|
655
|
+
const monthValueIsValid = (month) => {
|
|
656
|
+
|
|
657
|
+
// Guard clause: ensure month exists.
|
|
658
|
+
if (!month) {
|
|
659
|
+
return false;
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
// Convert month to number
|
|
663
|
+
const numMonth = Number.parseInt(month, 10);
|
|
664
|
+
|
|
665
|
+
// Guard clause: ensure month is a valid integer
|
|
666
|
+
if (Number.isNaN(numMonth)) {
|
|
667
|
+
throw new Error('AuroDatepickerUtilities | monthValueIsValid: Unable to parse month value integer');
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
// Guard clause: ensure month is within the valid range
|
|
671
|
+
if (numMonth < this.minMonth || numMonth > this.maxMonth) {
|
|
672
|
+
return false;
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
// Default return
|
|
676
|
+
return true;
|
|
677
|
+
};
|
|
678
|
+
|
|
679
|
+
// Validator for year
|
|
680
|
+
const yearIsValid = (_year) => {
|
|
681
|
+
|
|
682
|
+
// Guard clause: ensure year exists.
|
|
683
|
+
if (!_year) {
|
|
684
|
+
return false;
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
// Get the full year
|
|
688
|
+
const year = this.getFourDigitYear(_year);
|
|
689
|
+
|
|
690
|
+
// Convert year to number
|
|
691
|
+
const numYear = Number.parseInt(year, 10);
|
|
692
|
+
|
|
693
|
+
// Guard clause: ensure year is a valid integer
|
|
694
|
+
if (Number.isNaN(numYear)) {
|
|
695
|
+
throw new Error('AuroDatepickerUtilities | yearValueIsValid: Unable to parse year value integer');
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
// Guard clause: ensure year is within the valid range
|
|
699
|
+
if (numYear < this.minYear || numYear > this.maxYear) {
|
|
700
|
+
return false;
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
// Default return
|
|
704
|
+
return true;
|
|
705
|
+
};
|
|
706
|
+
|
|
707
|
+
// Self-contained checks for month, day, and year
|
|
708
|
+
const checks = [
|
|
709
|
+
monthValueIsValid(dateParts.month),
|
|
710
|
+
dayValueIsValid(dateParts.day),
|
|
711
|
+
yearIsValid(dateParts.year)
|
|
712
|
+
];
|
|
713
|
+
|
|
714
|
+
// If any of the checks failed, the date format does not match and the result is invalid
|
|
715
|
+
const isValid = checks.every((check) => check === true);
|
|
716
|
+
|
|
717
|
+
// If the check is invalid, return false
|
|
718
|
+
if (!isValid) {
|
|
719
|
+
return false;
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
// Default case
|
|
723
|
+
return true;
|
|
724
|
+
};
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
|
|
728
|
+
// Export a class instance
|
|
729
|
+
const dateUtilities = new AuroDateUtilities();
|
|
730
|
+
|
|
731
|
+
// Export the class instance methods individually
|
|
732
|
+
const {
|
|
733
|
+
datesMatch,
|
|
734
|
+
validDateStr,
|
|
735
|
+
dateAndFormatMatch,
|
|
736
|
+
minDay,
|
|
737
|
+
minMonth,
|
|
738
|
+
minYear,
|
|
739
|
+
maxDay,
|
|
740
|
+
maxMonth,
|
|
741
|
+
maxYear
|
|
742
|
+
} = dateUtilities;
|
|
743
|
+
|
|
744
|
+
const {
|
|
745
|
+
toNorthAmericanFormat,
|
|
746
|
+
parseDate,
|
|
747
|
+
getDateAsString
|
|
748
|
+
} = dateFormatter;
|
|
749
|
+
|
|
342
750
|
// Copyright (c) Alaska Air. All right reserved. Licensed under the Apache-2.0 license
|
|
343
751
|
// See LICENSE in the project root for license information.
|
|
344
752
|
|
|
345
753
|
|
|
346
754
|
class AuroFormValidation {
|
|
755
|
+
|
|
347
756
|
constructor() {
|
|
348
757
|
this.runtimeUtils = new AuroLibraryRuntimeUtils$1();
|
|
349
758
|
}
|
|
@@ -435,17 +844,17 @@ class AuroFormValidation {
|
|
|
435
844
|
]
|
|
436
845
|
}
|
|
437
846
|
};
|
|
438
|
-
|
|
847
|
+
|
|
439
848
|
let elementType;
|
|
440
849
|
if (this.runtimeUtils.elementMatch(elem, 'auro-input')) {
|
|
441
850
|
elementType = 'input';
|
|
442
851
|
} else if (this.runtimeUtils.elementMatch(elem, 'auro-counter') || this.runtimeUtils.elementMatch(elem, 'auro-counter-group')) {
|
|
443
852
|
elementType = 'counter';
|
|
444
853
|
}
|
|
445
|
-
|
|
854
|
+
|
|
446
855
|
if (elementType) {
|
|
447
856
|
const rules = validationRules[elementType];
|
|
448
|
-
|
|
857
|
+
|
|
449
858
|
if (rules) {
|
|
450
859
|
Object.values(rules).flat().forEach(rule => {
|
|
451
860
|
if (rule.check(elem)) {
|
|
@@ -471,48 +880,82 @@ class AuroFormValidation {
|
|
|
471
880
|
if (!elem.value.match(emailRegex)) {
|
|
472
881
|
elem.validity = 'patternMismatch';
|
|
473
882
|
elem.errorMessage = elem.setCustomValidityForType || elem.setCustomValidity || '';
|
|
883
|
+
return;
|
|
474
884
|
}
|
|
475
885
|
} else if (elem.type === 'credit-card') {
|
|
476
886
|
if (elem.value.length > 0 && elem.value.length < elem.validationCCLength) {
|
|
477
887
|
elem.validity = 'tooShort';
|
|
478
888
|
elem.errorMessage = elem.setCustomValidityForType || elem.setCustomValidity || '';
|
|
889
|
+
return;
|
|
479
890
|
}
|
|
480
891
|
} else if (elem.type === 'number') {
|
|
481
892
|
if (elem.max !== undefined && Number(elem.max) < Number(elem.value)) {
|
|
482
893
|
elem.validity = 'rangeOverflow';
|
|
483
894
|
elem.errorMessage = elem.setCustomValidityRangeOverflow || elem.setCustomValidity || '';
|
|
895
|
+
return;
|
|
484
896
|
}
|
|
485
897
|
|
|
486
898
|
if (elem.min !== undefined && elem.value?.length > 0 && Number(elem.min) > Number(elem.value)) {
|
|
487
899
|
elem.validity = 'rangeUnderflow';
|
|
488
900
|
elem.errorMessage = elem.setCustomValidityRangeUnderflow || elem.setCustomValidity || '';
|
|
901
|
+
return;
|
|
489
902
|
}
|
|
490
|
-
} else if (elem.type === 'date') {
|
|
491
|
-
|
|
903
|
+
} else if (elem.type === 'date' && elem.value?.length > 0) {
|
|
904
|
+
|
|
905
|
+
// Guard Clause: if the value is too short
|
|
906
|
+
if (elem.value.length < elem.lengthForType) {
|
|
907
|
+
|
|
492
908
|
elem.validity = 'tooShort';
|
|
493
909
|
elem.errorMessage = elem.setCustomValidityForType || elem.setCustomValidity || '';
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
910
|
+
return;
|
|
911
|
+
}
|
|
912
|
+
|
|
913
|
+
// Guard Clause: If the value is too long for the type
|
|
914
|
+
if (elem.value?.length > elem.lengthForType) {
|
|
915
|
+
|
|
916
|
+
elem.validity = 'tooLong';
|
|
917
|
+
elem.errorMessage = elem.setCustomValidityForType || elem.setCustomValidity || '';
|
|
918
|
+
return;
|
|
919
|
+
}
|
|
920
|
+
|
|
921
|
+
// Validate that the date passed was the correct format
|
|
922
|
+
if (!dateAndFormatMatch(elem.value, elem.format)) {
|
|
923
|
+
elem.validity = 'patternMismatch';
|
|
924
|
+
elem.errorMessage = elem.setCustomValidityForType || elem.setCustomValidity || 'Invalid Date Format Entered';
|
|
925
|
+
return;
|
|
926
|
+
}
|
|
927
|
+
|
|
928
|
+
// Validate that the date passed was a valid date
|
|
929
|
+
if (!validDateStr(elem.value, elem.format)) {
|
|
930
|
+
elem.validity = 'invalidDate';
|
|
931
|
+
elem.errorMessage = elem.setCustomValidityInvalidDate || elem.setCustomValidity || 'Invalid Date Entered';
|
|
932
|
+
return;
|
|
933
|
+
}
|
|
934
|
+
|
|
935
|
+
// Perform the rest of the validation
|
|
936
|
+
const formattedValue = toNorthAmericanFormat(elem.value, elem.format);
|
|
937
|
+
const valueDate = new Date(formattedValue);
|
|
938
|
+
|
|
939
|
+
// // Validate max date
|
|
940
|
+
if (elem.max?.length === elem.lengthForType) {
|
|
941
|
+
|
|
942
|
+
const maxDate = new Date(toNorthAmericanFormat(elem.max, elem.format));
|
|
943
|
+
|
|
944
|
+
if (valueDate > maxDate) {
|
|
945
|
+
elem.validity = 'rangeOverflow';
|
|
946
|
+
elem.errorMessage = elem.setCustomValidityRangeOverflow || elem.setCustomValidity || '';
|
|
947
|
+
return;
|
|
506
948
|
}
|
|
949
|
+
}
|
|
507
950
|
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
951
|
+
// Validate min date
|
|
952
|
+
if (elem.min?.length === elem.lengthForType) {
|
|
953
|
+
const minDate = new Date(toNorthAmericanFormat(elem.min, elem.format));
|
|
511
954
|
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
955
|
+
if (valueDate < minDate) {
|
|
956
|
+
elem.validity = 'rangeUnderflow';
|
|
957
|
+
elem.errorMessage = elem.setCustomValidityRangeUnderflow || elem.setCustomValidity || '';
|
|
958
|
+
return;
|
|
516
959
|
}
|
|
517
960
|
}
|
|
518
961
|
}
|
|
@@ -631,7 +1074,7 @@ class AuroFormValidation {
|
|
|
631
1074
|
if (input.validationMessage.length > 0) {
|
|
632
1075
|
elem.errorMessage = input.validationMessage;
|
|
633
1076
|
}
|
|
634
|
-
} else if (this.inputElements?.length > 0
|
|
1077
|
+
} else if (this.inputElements?.length > 0 && elem.errorMessage === '') {
|
|
635
1078
|
const firstInput = this.inputElements[0];
|
|
636
1079
|
|
|
637
1080
|
if (firstInput.validationMessage.length > 0) {
|
|
@@ -106,7 +106,7 @@ The use of any Auro custom element has a dependency on the [Auro Design Tokens](
|
|
|
106
106
|
In cases where the project is not able to process JS assets, there are pre-processed assets available for use. Legacy browsers such as IE11 are no longer supported.
|
|
107
107
|
|
|
108
108
|
```html
|
|
109
|
-
<script type="module" src="https://cdn.jsdelivr.net/npm/@aurodesignsystem/auro-formkit@3.0
|
|
109
|
+
<script type="module" src="https://cdn.jsdelivr.net/npm/@aurodesignsystem/auro-formkit@3.1.0/auro-checkbox/+esm"></script>
|
|
110
110
|
```
|
|
111
111
|
<!-- AURO-GENERATED-CONTENT:END -->
|
|
112
112
|
|