@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
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Semantic Release Automated Changelog
|
|
2
2
|
|
|
3
|
-
# [3.
|
|
3
|
+
# [3.2.0-beta.1](https://github.com/AlaskaAirlines/auro-formkit/compare/v3.1.0...v3.2.0-beta.1) (2025-04-30)
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
### Bug Fixes
|
|
@@ -12,6 +12,24 @@
|
|
|
12
12
|
|
|
13
13
|
* surface fullscreenBreakpoint with new `disabled` value ([4f00b48](https://github.com/AlaskaAirlines/auro-formkit/commit/4f00b4808254490419ca6ae387344e49834ca896))
|
|
14
14
|
|
|
15
|
+
# [3.1.0](https://github.com/AlaskaAirlines/auro-formkit/compare/v3.0.1...v3.1.0) (2025-04-30)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### Bug Fixes
|
|
19
|
+
|
|
20
|
+
* Fix accessibility for auro-combobox ([4619710](https://github.com/AlaskaAirlines/auro-formkit/commit/46197100af6612c381846128640f49260851316b))
|
|
21
|
+
* move all a11y tags in triggerElement for dropdown, adding combobox a11y test ([f8f7575](https://github.com/AlaskaAirlines/auro-formkit/commit/f8f757515a8d75fb1f67c42622709cd237bf1508))
|
|
22
|
+
* move all a11y tags in triggerElement for dropdown, adding combobox a11y test ([6930630](https://github.com/AlaskaAirlines/auro-formkit/commit/6930630f52b200b852313ccef5bd5cf816e64097))
|
|
23
|
+
* put id on dropdown trigger's slot ([8b4153e](https://github.com/AlaskaAirlines/auro-formkit/commit/8b4153e279ae7a9f340958784c14aca00dc1f4ae))
|
|
24
|
+
* resolve issues with accessibility for combobox and select components ([b75949c](https://github.com/AlaskaAirlines/auro-formkit/commit/b75949c90048d0739c20c936a74207443abdfee6))
|
|
25
|
+
* set role and autocomplete values as props not attr ([46f3a79](https://github.com/AlaskaAirlines/auro-formkit/commit/46f3a792246923f3b4b06f19ff88a0e66353139a))
|
|
26
|
+
* set the aria-* on trigger slotted node ([bd0ee3c](https://github.com/AlaskaAirlines/auro-formkit/commit/bd0ee3c05e65d00a8706b252e588f48b1623acb7))
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
### Features
|
|
30
|
+
|
|
31
|
+
* datepicker now validates that date passed is valid and matches provided format ([3059aa4](https://github.com/AlaskaAirlines/auro-formkit/commit/3059aa40d1a57e21f9b4cfbf83295e1ee2d75615))
|
|
32
|
+
|
|
15
33
|
## [3.0.1](https://github.com/AlaskaAirlines/auro-formkit/compare/v3.0.0...v3.0.1) (2025-04-29)
|
|
16
34
|
|
|
17
35
|
|
|
@@ -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
|
|
|
@@ -347,11 +347,420 @@ class AuroCheckbox extends r {
|
|
|
347
347
|
*/
|
|
348
348
|
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);
|
|
349
349
|
|
|
350
|
+
class DateFormatter {
|
|
351
|
+
|
|
352
|
+
constructor() {
|
|
353
|
+
|
|
354
|
+
/**
|
|
355
|
+
* @description Parses a date string into its components.
|
|
356
|
+
* @param {string} dateStr - Date string to parse.
|
|
357
|
+
* @param {string} format - Date format to parse.
|
|
358
|
+
* @returns {Object<key["month" | "day" | "year"]: number>|undefined}
|
|
359
|
+
*/
|
|
360
|
+
this.parseDate = (dateStr, format = 'mm/dd/yyyy') => {
|
|
361
|
+
|
|
362
|
+
// Guard Clause: Date string is defined
|
|
363
|
+
if (!dateStr) {
|
|
364
|
+
return undefined;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
// Assume the separator is a "/" a defined in our code base
|
|
368
|
+
const separator = '/';
|
|
369
|
+
|
|
370
|
+
// Get the parts of the date and format
|
|
371
|
+
const valueParts = dateStr.split(separator);
|
|
372
|
+
const formatParts = format.split(separator);
|
|
373
|
+
|
|
374
|
+
// Check if the value and format have the correct number of parts
|
|
375
|
+
if (valueParts.length !== formatParts.length) {
|
|
376
|
+
throw new Error('AuroDatepickerUtilities | parseDate: Date string and format length do not match');
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
// Holds the result to be returned
|
|
380
|
+
const result = formatParts.reduce((acc, part, index) => {
|
|
381
|
+
const value = valueParts[index];
|
|
382
|
+
|
|
383
|
+
if ((/m/iu).test(part)) {
|
|
384
|
+
acc.month = value;
|
|
385
|
+
} else if ((/d/iu).test(part)) {
|
|
386
|
+
acc.day = value;
|
|
387
|
+
} else if ((/y/iu).test(part)) {
|
|
388
|
+
acc.year = value;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
return acc;
|
|
392
|
+
}, {});
|
|
393
|
+
|
|
394
|
+
// If we found all the parts, return the result
|
|
395
|
+
if (result.month && result.year) {
|
|
396
|
+
return result;
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
// Throw an error to let the dev know we were unable to parse the date string
|
|
400
|
+
throw new Error('AuroDatepickerUtilities | parseDate: Unable to parse date string');
|
|
401
|
+
};
|
|
402
|
+
|
|
403
|
+
/**
|
|
404
|
+
* Convert a date object to string format.
|
|
405
|
+
* @param {Object} date - Date to convert to string.
|
|
406
|
+
* @returns {Object} Returns the date as a string.
|
|
407
|
+
*/
|
|
408
|
+
this.getDateAsString = (date) => date.toLocaleDateString(undefined, {
|
|
409
|
+
year: "numeric",
|
|
410
|
+
month: "2-digit",
|
|
411
|
+
day: "2-digit",
|
|
412
|
+
});
|
|
413
|
+
|
|
414
|
+
/**
|
|
415
|
+
* Converts a date string to a North American date format.
|
|
416
|
+
* @param {String} dateStr - Date to validate.
|
|
417
|
+
* @param {String} format - Date format to validate against.
|
|
418
|
+
* @returns {Boolean}
|
|
419
|
+
*/
|
|
420
|
+
this.toNorthAmericanFormat = (dateStr, format) => {
|
|
421
|
+
|
|
422
|
+
if (format === 'mm/dd/yyyy') {
|
|
423
|
+
return dateStr;
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
const parsedDate = this.parseDate(dateStr, format);
|
|
427
|
+
|
|
428
|
+
if (!parsedDate) {
|
|
429
|
+
throw new Error('AuroDatepickerUtilities | toNorthAmericanFormat: Unable to parse date string');
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
const { month, day, year } = parsedDate;
|
|
433
|
+
|
|
434
|
+
const dateParts = [];
|
|
435
|
+
if (month) {
|
|
436
|
+
dateParts.push(month);
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
if (day) {
|
|
440
|
+
dateParts.push(day);
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
if (year) {
|
|
444
|
+
dateParts.push(year);
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
return dateParts.join('/');
|
|
448
|
+
};
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
const dateFormatter = new DateFormatter();
|
|
452
|
+
|
|
453
|
+
// filepath: dateConstraints.mjs
|
|
454
|
+
const DATE_UTIL_CONSTRAINTS = {
|
|
455
|
+
maxDay: 31,
|
|
456
|
+
maxMonth: 12,
|
|
457
|
+
maxYear: 2400,
|
|
458
|
+
minDay: 1,
|
|
459
|
+
minMonth: 1,
|
|
460
|
+
minYear: 1900,
|
|
461
|
+
};
|
|
462
|
+
|
|
463
|
+
class AuroDateUtilitiesBase {
|
|
464
|
+
|
|
465
|
+
/**
|
|
466
|
+
* @description The maximum day value allowed by the various utilities in this class.
|
|
467
|
+
* @readonly
|
|
468
|
+
* @type {Number}
|
|
469
|
+
*/
|
|
470
|
+
get maxDay() {
|
|
471
|
+
return DATE_UTIL_CONSTRAINTS.maxDay;
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
/**
|
|
475
|
+
* @description The maximum month value allowed by the various utilities in this class.
|
|
476
|
+
* @readonly
|
|
477
|
+
* @type {Number}
|
|
478
|
+
*/
|
|
479
|
+
get maxMonth() {
|
|
480
|
+
return DATE_UTIL_CONSTRAINTS.maxMonth;
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
/**
|
|
484
|
+
* @description The maximum year value allowed by the various utilities in this class.
|
|
485
|
+
* @readonly
|
|
486
|
+
* @type {Number}
|
|
487
|
+
*/
|
|
488
|
+
get maxYear() {
|
|
489
|
+
return DATE_UTIL_CONSTRAINTS.maxYear;
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
/**
|
|
493
|
+
* @description The minimum day value allowed by the various utilities in this class.
|
|
494
|
+
* @readonly
|
|
495
|
+
* @type {Number}
|
|
496
|
+
*/
|
|
497
|
+
get minDay() {
|
|
498
|
+
return DATE_UTIL_CONSTRAINTS.minDay;
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
/**
|
|
502
|
+
* @description The minimum month value allowed by the various utilities in this class.
|
|
503
|
+
* @readonly
|
|
504
|
+
* @type {Number}
|
|
505
|
+
*/
|
|
506
|
+
get minMonth() {
|
|
507
|
+
return DATE_UTIL_CONSTRAINTS.minMonth;
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
/**
|
|
511
|
+
* @description The minimum year value allowed by the various utilities in this class.
|
|
512
|
+
* @readonly
|
|
513
|
+
* @type {Number}
|
|
514
|
+
*/
|
|
515
|
+
get minYear() {
|
|
516
|
+
return DATE_UTIL_CONSTRAINTS.minYear;
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
/* eslint-disable no-magic-numbers */
|
|
521
|
+
|
|
522
|
+
class AuroDateUtilities extends AuroDateUtilitiesBase {
|
|
523
|
+
|
|
524
|
+
/**
|
|
525
|
+
* Returns the current century.
|
|
526
|
+
* @returns {String} The current century.
|
|
527
|
+
*/
|
|
528
|
+
getCentury () {
|
|
529
|
+
return String(new Date().getFullYear()).slice(0, 2);
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
/**
|
|
533
|
+
* Returns a four digit year.
|
|
534
|
+
* @param {String} year - The year to convert to four digits.
|
|
535
|
+
* @returns {String} The four digit year.
|
|
536
|
+
*/
|
|
537
|
+
getFourDigitYear (year) {
|
|
538
|
+
|
|
539
|
+
const strYear = String(year).trim();
|
|
540
|
+
return strYear.length <= 2 ? this.getCentury() + strYear : strYear;
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
constructor() {
|
|
544
|
+
|
|
545
|
+
super();
|
|
546
|
+
|
|
547
|
+
/**
|
|
548
|
+
* Compares two dates to see if they match.
|
|
549
|
+
* @param {Object} date1 - First date to compare.
|
|
550
|
+
* @param {Object} date2 - Second date to compare.
|
|
551
|
+
* @returns {Boolean} Returns true if the dates match.
|
|
552
|
+
*/
|
|
553
|
+
this.datesMatch = (date1, date2) => new Date(date1).getTime() === new Date(date2).getTime();
|
|
554
|
+
|
|
555
|
+
/**
|
|
556
|
+
* Returns true if value passed in is a valid date.
|
|
557
|
+
* @param {String} date - Date to validate.
|
|
558
|
+
* @param {String} format - Date format to validate against.
|
|
559
|
+
* @returns {Boolean}
|
|
560
|
+
*/
|
|
561
|
+
this.validDateStr = (date, format) => {
|
|
562
|
+
|
|
563
|
+
// The length we expect the date string to be
|
|
564
|
+
const dateStrLength = format.length;
|
|
565
|
+
|
|
566
|
+
// Guard Clause: Date and format are defined
|
|
567
|
+
if (typeof date === "undefined" || typeof format === "undefined") {
|
|
568
|
+
throw new Error('AuroDatepickerUtilities | validateDateStr: Date and format are required');
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
// Guard Clause: Date should be of type string
|
|
572
|
+
if (typeof date !== "string") {
|
|
573
|
+
throw new Error('AuroDatepickerUtilities | validateDateStr: Date must be a string');
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
// Guard Clause: Format should be of type string
|
|
577
|
+
if (typeof format !== "string") {
|
|
578
|
+
throw new Error('AuroDatepickerUtilities | validateDateStr: Format must be a string');
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
// Guard Clause: Length is what we expect it to be
|
|
582
|
+
if (date.length !== dateStrLength) {
|
|
583
|
+
return false;
|
|
584
|
+
}
|
|
585
|
+
// Get a formatted date string and parse it
|
|
586
|
+
const dateParts = dateFormatter.parseDate(date, format);
|
|
587
|
+
|
|
588
|
+
// Guard Clause: Date parse succeeded
|
|
589
|
+
if (!dateParts) {
|
|
590
|
+
return false;
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
// Create the expected date string based on the date parts
|
|
594
|
+
const expectedDateStr = `${dateParts.month}/${dateParts.day || "01"}/${this.getFourDigitYear(dateParts.year)}`;
|
|
595
|
+
|
|
596
|
+
// Generate a date object that we will extract a string date from to compare to the passed in date string
|
|
597
|
+
const dateObj = new Date(this.getFourDigitYear(dateParts.year), dateParts.month - 1, dateParts.day || 1);
|
|
598
|
+
|
|
599
|
+
// Get the date string of the date object we created from the string date
|
|
600
|
+
const actualDateStr = dateFormatter.getDateAsString(dateObj);
|
|
601
|
+
|
|
602
|
+
// Guard Clause: Generated date matches date string input
|
|
603
|
+
if (expectedDateStr !== actualDateStr) {
|
|
604
|
+
return false;
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
// If we passed all other checks, we can assume the date is valid
|
|
608
|
+
return true;
|
|
609
|
+
};
|
|
610
|
+
|
|
611
|
+
/**
|
|
612
|
+
* Determines if a string date value matches the format provided.
|
|
613
|
+
* @param {string} value = The date string value.
|
|
614
|
+
* @param { string} format = The date format to match against.
|
|
615
|
+
* @returns {boolean}
|
|
616
|
+
*/
|
|
617
|
+
this.dateAndFormatMatch = (value, format) => {
|
|
618
|
+
|
|
619
|
+
// Ensure we have both values we need to do the comparison
|
|
620
|
+
if (!value || !format) {
|
|
621
|
+
throw new Error('AuroFormValidation | dateFormatMatch: value and format are required');
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
// If the lengths are different, they cannot match
|
|
625
|
+
if (value.length !== format.length) {
|
|
626
|
+
return false;
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
// Get the parts of the date
|
|
630
|
+
const dateParts = dateFormatter.parseDate(value, format);
|
|
631
|
+
|
|
632
|
+
// Validator for day
|
|
633
|
+
const dayValueIsValid = (day) => {
|
|
634
|
+
|
|
635
|
+
// Guard clause: if there is no day in the dateParts, we can ignore this check.
|
|
636
|
+
if (!dateParts.day) {
|
|
637
|
+
return true;
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
// Guard clause: ensure day exists.
|
|
641
|
+
if (!day) {
|
|
642
|
+
return false;
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
// Convert day to number
|
|
646
|
+
const numDay = Number.parseInt(day, 10);
|
|
647
|
+
|
|
648
|
+
// Guard clause: ensure day is a valid integer
|
|
649
|
+
if (Number.isNaN(numDay)) {
|
|
650
|
+
throw new Error('AuroDatepickerUtilities | dayValueIsValid: Unable to parse day value integer');
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
// Guard clause: ensure day is within the valid range
|
|
654
|
+
if (numDay < this.minDay || numDay > this.maxDay) {
|
|
655
|
+
return false;
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
// Default return
|
|
659
|
+
return true;
|
|
660
|
+
};
|
|
661
|
+
|
|
662
|
+
// Validator for month
|
|
663
|
+
const monthValueIsValid = (month) => {
|
|
664
|
+
|
|
665
|
+
// Guard clause: ensure month exists.
|
|
666
|
+
if (!month) {
|
|
667
|
+
return false;
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
// Convert month to number
|
|
671
|
+
const numMonth = Number.parseInt(month, 10);
|
|
672
|
+
|
|
673
|
+
// Guard clause: ensure month is a valid integer
|
|
674
|
+
if (Number.isNaN(numMonth)) {
|
|
675
|
+
throw new Error('AuroDatepickerUtilities | monthValueIsValid: Unable to parse month value integer');
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
// Guard clause: ensure month is within the valid range
|
|
679
|
+
if (numMonth < this.minMonth || numMonth > this.maxMonth) {
|
|
680
|
+
return false;
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
// Default return
|
|
684
|
+
return true;
|
|
685
|
+
};
|
|
686
|
+
|
|
687
|
+
// Validator for year
|
|
688
|
+
const yearIsValid = (_year) => {
|
|
689
|
+
|
|
690
|
+
// Guard clause: ensure year exists.
|
|
691
|
+
if (!_year) {
|
|
692
|
+
return false;
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
// Get the full year
|
|
696
|
+
const year = this.getFourDigitYear(_year);
|
|
697
|
+
|
|
698
|
+
// Convert year to number
|
|
699
|
+
const numYear = Number.parseInt(year, 10);
|
|
700
|
+
|
|
701
|
+
// Guard clause: ensure year is a valid integer
|
|
702
|
+
if (Number.isNaN(numYear)) {
|
|
703
|
+
throw new Error('AuroDatepickerUtilities | yearValueIsValid: Unable to parse year value integer');
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
// Guard clause: ensure year is within the valid range
|
|
707
|
+
if (numYear < this.minYear || numYear > this.maxYear) {
|
|
708
|
+
return false;
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
// Default return
|
|
712
|
+
return true;
|
|
713
|
+
};
|
|
714
|
+
|
|
715
|
+
// Self-contained checks for month, day, and year
|
|
716
|
+
const checks = [
|
|
717
|
+
monthValueIsValid(dateParts.month),
|
|
718
|
+
dayValueIsValid(dateParts.day),
|
|
719
|
+
yearIsValid(dateParts.year)
|
|
720
|
+
];
|
|
721
|
+
|
|
722
|
+
// If any of the checks failed, the date format does not match and the result is invalid
|
|
723
|
+
const isValid = checks.every((check) => check === true);
|
|
724
|
+
|
|
725
|
+
// If the check is invalid, return false
|
|
726
|
+
if (!isValid) {
|
|
727
|
+
return false;
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
// Default case
|
|
731
|
+
return true;
|
|
732
|
+
};
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
// Export a class instance
|
|
737
|
+
const dateUtilities = new AuroDateUtilities();
|
|
738
|
+
|
|
739
|
+
// Export the class instance methods individually
|
|
740
|
+
const {
|
|
741
|
+
datesMatch,
|
|
742
|
+
validDateStr,
|
|
743
|
+
dateAndFormatMatch,
|
|
744
|
+
minDay,
|
|
745
|
+
minMonth,
|
|
746
|
+
minYear,
|
|
747
|
+
maxDay,
|
|
748
|
+
maxMonth,
|
|
749
|
+
maxYear
|
|
750
|
+
} = dateUtilities;
|
|
751
|
+
|
|
752
|
+
const {
|
|
753
|
+
toNorthAmericanFormat,
|
|
754
|
+
parseDate,
|
|
755
|
+
getDateAsString
|
|
756
|
+
} = dateFormatter;
|
|
757
|
+
|
|
350
758
|
// Copyright (c) Alaska Air. All right reserved. Licensed under the Apache-2.0 license
|
|
351
759
|
// See LICENSE in the project root for license information.
|
|
352
760
|
|
|
353
761
|
|
|
354
762
|
class AuroFormValidation {
|
|
763
|
+
|
|
355
764
|
constructor() {
|
|
356
765
|
this.runtimeUtils = new AuroLibraryRuntimeUtils$1();
|
|
357
766
|
}
|
|
@@ -443,17 +852,17 @@ class AuroFormValidation {
|
|
|
443
852
|
]
|
|
444
853
|
}
|
|
445
854
|
};
|
|
446
|
-
|
|
855
|
+
|
|
447
856
|
let elementType;
|
|
448
857
|
if (this.runtimeUtils.elementMatch(elem, 'auro-input')) {
|
|
449
858
|
elementType = 'input';
|
|
450
859
|
} else if (this.runtimeUtils.elementMatch(elem, 'auro-counter') || this.runtimeUtils.elementMatch(elem, 'auro-counter-group')) {
|
|
451
860
|
elementType = 'counter';
|
|
452
861
|
}
|
|
453
|
-
|
|
862
|
+
|
|
454
863
|
if (elementType) {
|
|
455
864
|
const rules = validationRules[elementType];
|
|
456
|
-
|
|
865
|
+
|
|
457
866
|
if (rules) {
|
|
458
867
|
Object.values(rules).flat().forEach(rule => {
|
|
459
868
|
if (rule.check(elem)) {
|
|
@@ -479,48 +888,82 @@ class AuroFormValidation {
|
|
|
479
888
|
if (!elem.value.match(emailRegex)) {
|
|
480
889
|
elem.validity = 'patternMismatch';
|
|
481
890
|
elem.errorMessage = elem.setCustomValidityForType || elem.setCustomValidity || '';
|
|
891
|
+
return;
|
|
482
892
|
}
|
|
483
893
|
} else if (elem.type === 'credit-card') {
|
|
484
894
|
if (elem.value.length > 0 && elem.value.length < elem.validationCCLength) {
|
|
485
895
|
elem.validity = 'tooShort';
|
|
486
896
|
elem.errorMessage = elem.setCustomValidityForType || elem.setCustomValidity || '';
|
|
897
|
+
return;
|
|
487
898
|
}
|
|
488
899
|
} else if (elem.type === 'number') {
|
|
489
900
|
if (elem.max !== undefined && Number(elem.max) < Number(elem.value)) {
|
|
490
901
|
elem.validity = 'rangeOverflow';
|
|
491
902
|
elem.errorMessage = elem.setCustomValidityRangeOverflow || elem.setCustomValidity || '';
|
|
903
|
+
return;
|
|
492
904
|
}
|
|
493
905
|
|
|
494
906
|
if (elem.min !== undefined && elem.value?.length > 0 && Number(elem.min) > Number(elem.value)) {
|
|
495
907
|
elem.validity = 'rangeUnderflow';
|
|
496
908
|
elem.errorMessage = elem.setCustomValidityRangeUnderflow || elem.setCustomValidity || '';
|
|
909
|
+
return;
|
|
497
910
|
}
|
|
498
|
-
} else if (elem.type === 'date') {
|
|
499
|
-
|
|
911
|
+
} else if (elem.type === 'date' && elem.value?.length > 0) {
|
|
912
|
+
|
|
913
|
+
// Guard Clause: if the value is too short
|
|
914
|
+
if (elem.value.length < elem.lengthForType) {
|
|
915
|
+
|
|
500
916
|
elem.validity = 'tooShort';
|
|
501
917
|
elem.errorMessage = elem.setCustomValidityForType || elem.setCustomValidity || '';
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
918
|
+
return;
|
|
919
|
+
}
|
|
920
|
+
|
|
921
|
+
// Guard Clause: If the value is too long for the type
|
|
922
|
+
if (elem.value?.length > elem.lengthForType) {
|
|
923
|
+
|
|
924
|
+
elem.validity = 'tooLong';
|
|
925
|
+
elem.errorMessage = elem.setCustomValidityForType || elem.setCustomValidity || '';
|
|
926
|
+
return;
|
|
927
|
+
}
|
|
928
|
+
|
|
929
|
+
// Validate that the date passed was the correct format
|
|
930
|
+
if (!dateAndFormatMatch(elem.value, elem.format)) {
|
|
931
|
+
elem.validity = 'patternMismatch';
|
|
932
|
+
elem.errorMessage = elem.setCustomValidityForType || elem.setCustomValidity || 'Invalid Date Format Entered';
|
|
933
|
+
return;
|
|
934
|
+
}
|
|
935
|
+
|
|
936
|
+
// Validate that the date passed was a valid date
|
|
937
|
+
if (!validDateStr(elem.value, elem.format)) {
|
|
938
|
+
elem.validity = 'invalidDate';
|
|
939
|
+
elem.errorMessage = elem.setCustomValidityInvalidDate || elem.setCustomValidity || 'Invalid Date Entered';
|
|
940
|
+
return;
|
|
941
|
+
}
|
|
942
|
+
|
|
943
|
+
// Perform the rest of the validation
|
|
944
|
+
const formattedValue = toNorthAmericanFormat(elem.value, elem.format);
|
|
945
|
+
const valueDate = new Date(formattedValue);
|
|
946
|
+
|
|
947
|
+
// // Validate max date
|
|
948
|
+
if (elem.max?.length === elem.lengthForType) {
|
|
949
|
+
|
|
950
|
+
const maxDate = new Date(toNorthAmericanFormat(elem.max, elem.format));
|
|
951
|
+
|
|
952
|
+
if (valueDate > maxDate) {
|
|
953
|
+
elem.validity = 'rangeOverflow';
|
|
954
|
+
elem.errorMessage = elem.setCustomValidityRangeOverflow || elem.setCustomValidity || '';
|
|
955
|
+
return;
|
|
514
956
|
}
|
|
957
|
+
}
|
|
515
958
|
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
959
|
+
// Validate min date
|
|
960
|
+
if (elem.min?.length === elem.lengthForType) {
|
|
961
|
+
const minDate = new Date(toNorthAmericanFormat(elem.min, elem.format));
|
|
519
962
|
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
963
|
+
if (valueDate < minDate) {
|
|
964
|
+
elem.validity = 'rangeUnderflow';
|
|
965
|
+
elem.errorMessage = elem.setCustomValidityRangeUnderflow || elem.setCustomValidity || '';
|
|
966
|
+
return;
|
|
524
967
|
}
|
|
525
968
|
}
|
|
526
969
|
}
|
|
@@ -639,7 +1082,7 @@ class AuroFormValidation {
|
|
|
639
1082
|
if (input.validationMessage.length > 0) {
|
|
640
1083
|
elem.errorMessage = input.validationMessage;
|
|
641
1084
|
}
|
|
642
|
-
} else if (this.inputElements?.length > 0
|
|
1085
|
+
} else if (this.inputElements?.length > 0 && elem.errorMessage === '') {
|
|
643
1086
|
const firstInput = this.inputElements[0];
|
|
644
1087
|
|
|
645
1088
|
if (firstInput.validationMessage.length > 0) {
|