@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
|
@@ -292,11 +292,420 @@ class AuroCheckbox extends LitElement {
|
|
|
292
292
|
}
|
|
293
293
|
}
|
|
294
294
|
|
|
295
|
+
class DateFormatter {
|
|
296
|
+
|
|
297
|
+
constructor() {
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* @description Parses a date string into its components.
|
|
301
|
+
* @param {string} dateStr - Date string to parse.
|
|
302
|
+
* @param {string} format - Date format to parse.
|
|
303
|
+
* @returns {Object<key["month" | "day" | "year"]: number>|undefined}
|
|
304
|
+
*/
|
|
305
|
+
this.parseDate = (dateStr, format = 'mm/dd/yyyy') => {
|
|
306
|
+
|
|
307
|
+
// Guard Clause: Date string is defined
|
|
308
|
+
if (!dateStr) {
|
|
309
|
+
return undefined;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
// Assume the separator is a "/" a defined in our code base
|
|
313
|
+
const separator = '/';
|
|
314
|
+
|
|
315
|
+
// Get the parts of the date and format
|
|
316
|
+
const valueParts = dateStr.split(separator);
|
|
317
|
+
const formatParts = format.split(separator);
|
|
318
|
+
|
|
319
|
+
// Check if the value and format have the correct number of parts
|
|
320
|
+
if (valueParts.length !== formatParts.length) {
|
|
321
|
+
throw new Error('AuroDatepickerUtilities | parseDate: Date string and format length do not match');
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
// Holds the result to be returned
|
|
325
|
+
const result = formatParts.reduce((acc, part, index) => {
|
|
326
|
+
const value = valueParts[index];
|
|
327
|
+
|
|
328
|
+
if ((/m/iu).test(part)) {
|
|
329
|
+
acc.month = value;
|
|
330
|
+
} else if ((/d/iu).test(part)) {
|
|
331
|
+
acc.day = value;
|
|
332
|
+
} else if ((/y/iu).test(part)) {
|
|
333
|
+
acc.year = value;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
return acc;
|
|
337
|
+
}, {});
|
|
338
|
+
|
|
339
|
+
// If we found all the parts, return the result
|
|
340
|
+
if (result.month && result.year) {
|
|
341
|
+
return result;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
// Throw an error to let the dev know we were unable to parse the date string
|
|
345
|
+
throw new Error('AuroDatepickerUtilities | parseDate: Unable to parse date string');
|
|
346
|
+
};
|
|
347
|
+
|
|
348
|
+
/**
|
|
349
|
+
* Convert a date object to string format.
|
|
350
|
+
* @param {Object} date - Date to convert to string.
|
|
351
|
+
* @returns {Object} Returns the date as a string.
|
|
352
|
+
*/
|
|
353
|
+
this.getDateAsString = (date) => date.toLocaleDateString(undefined, {
|
|
354
|
+
year: "numeric",
|
|
355
|
+
month: "2-digit",
|
|
356
|
+
day: "2-digit",
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
/**
|
|
360
|
+
* Converts a date string to a North American date format.
|
|
361
|
+
* @param {String} dateStr - Date to validate.
|
|
362
|
+
* @param {String} format - Date format to validate against.
|
|
363
|
+
* @returns {Boolean}
|
|
364
|
+
*/
|
|
365
|
+
this.toNorthAmericanFormat = (dateStr, format) => {
|
|
366
|
+
|
|
367
|
+
if (format === 'mm/dd/yyyy') {
|
|
368
|
+
return dateStr;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
const parsedDate = this.parseDate(dateStr, format);
|
|
372
|
+
|
|
373
|
+
if (!parsedDate) {
|
|
374
|
+
throw new Error('AuroDatepickerUtilities | toNorthAmericanFormat: Unable to parse date string');
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
const { month, day, year } = parsedDate;
|
|
378
|
+
|
|
379
|
+
const dateParts = [];
|
|
380
|
+
if (month) {
|
|
381
|
+
dateParts.push(month);
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
if (day) {
|
|
385
|
+
dateParts.push(day);
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
if (year) {
|
|
389
|
+
dateParts.push(year);
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
return dateParts.join('/');
|
|
393
|
+
};
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
const dateFormatter = new DateFormatter();
|
|
397
|
+
|
|
398
|
+
// filepath: dateConstraints.mjs
|
|
399
|
+
const DATE_UTIL_CONSTRAINTS = {
|
|
400
|
+
maxDay: 31,
|
|
401
|
+
maxMonth: 12,
|
|
402
|
+
maxYear: 2400,
|
|
403
|
+
minDay: 1,
|
|
404
|
+
minMonth: 1,
|
|
405
|
+
minYear: 1900,
|
|
406
|
+
};
|
|
407
|
+
|
|
408
|
+
class AuroDateUtilitiesBase {
|
|
409
|
+
|
|
410
|
+
/**
|
|
411
|
+
* @description The maximum day value allowed by the various utilities in this class.
|
|
412
|
+
* @readonly
|
|
413
|
+
* @type {Number}
|
|
414
|
+
*/
|
|
415
|
+
get maxDay() {
|
|
416
|
+
return DATE_UTIL_CONSTRAINTS.maxDay;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
/**
|
|
420
|
+
* @description The maximum month value allowed by the various utilities in this class.
|
|
421
|
+
* @readonly
|
|
422
|
+
* @type {Number}
|
|
423
|
+
*/
|
|
424
|
+
get maxMonth() {
|
|
425
|
+
return DATE_UTIL_CONSTRAINTS.maxMonth;
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
/**
|
|
429
|
+
* @description The maximum year value allowed by the various utilities in this class.
|
|
430
|
+
* @readonly
|
|
431
|
+
* @type {Number}
|
|
432
|
+
*/
|
|
433
|
+
get maxYear() {
|
|
434
|
+
return DATE_UTIL_CONSTRAINTS.maxYear;
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
/**
|
|
438
|
+
* @description The minimum day value allowed by the various utilities in this class.
|
|
439
|
+
* @readonly
|
|
440
|
+
* @type {Number}
|
|
441
|
+
*/
|
|
442
|
+
get minDay() {
|
|
443
|
+
return DATE_UTIL_CONSTRAINTS.minDay;
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
/**
|
|
447
|
+
* @description The minimum month value allowed by the various utilities in this class.
|
|
448
|
+
* @readonly
|
|
449
|
+
* @type {Number}
|
|
450
|
+
*/
|
|
451
|
+
get minMonth() {
|
|
452
|
+
return DATE_UTIL_CONSTRAINTS.minMonth;
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
/**
|
|
456
|
+
* @description The minimum year value allowed by the various utilities in this class.
|
|
457
|
+
* @readonly
|
|
458
|
+
* @type {Number}
|
|
459
|
+
*/
|
|
460
|
+
get minYear() {
|
|
461
|
+
return DATE_UTIL_CONSTRAINTS.minYear;
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
/* eslint-disable no-magic-numbers */
|
|
466
|
+
|
|
467
|
+
class AuroDateUtilities extends AuroDateUtilitiesBase {
|
|
468
|
+
|
|
469
|
+
/**
|
|
470
|
+
* Returns the current century.
|
|
471
|
+
* @returns {String} The current century.
|
|
472
|
+
*/
|
|
473
|
+
getCentury () {
|
|
474
|
+
return String(new Date().getFullYear()).slice(0, 2);
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
/**
|
|
478
|
+
* Returns a four digit year.
|
|
479
|
+
* @param {String} year - The year to convert to four digits.
|
|
480
|
+
* @returns {String} The four digit year.
|
|
481
|
+
*/
|
|
482
|
+
getFourDigitYear (year) {
|
|
483
|
+
|
|
484
|
+
const strYear = String(year).trim();
|
|
485
|
+
return strYear.length <= 2 ? this.getCentury() + strYear : strYear;
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
constructor() {
|
|
489
|
+
|
|
490
|
+
super();
|
|
491
|
+
|
|
492
|
+
/**
|
|
493
|
+
* Compares two dates to see if they match.
|
|
494
|
+
* @param {Object} date1 - First date to compare.
|
|
495
|
+
* @param {Object} date2 - Second date to compare.
|
|
496
|
+
* @returns {Boolean} Returns true if the dates match.
|
|
497
|
+
*/
|
|
498
|
+
this.datesMatch = (date1, date2) => new Date(date1).getTime() === new Date(date2).getTime();
|
|
499
|
+
|
|
500
|
+
/**
|
|
501
|
+
* Returns true if value passed in is a valid date.
|
|
502
|
+
* @param {String} date - Date to validate.
|
|
503
|
+
* @param {String} format - Date format to validate against.
|
|
504
|
+
* @returns {Boolean}
|
|
505
|
+
*/
|
|
506
|
+
this.validDateStr = (date, format) => {
|
|
507
|
+
|
|
508
|
+
// The length we expect the date string to be
|
|
509
|
+
const dateStrLength = format.length;
|
|
510
|
+
|
|
511
|
+
// Guard Clause: Date and format are defined
|
|
512
|
+
if (typeof date === "undefined" || typeof format === "undefined") {
|
|
513
|
+
throw new Error('AuroDatepickerUtilities | validateDateStr: Date and format are required');
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
// Guard Clause: Date should be of type string
|
|
517
|
+
if (typeof date !== "string") {
|
|
518
|
+
throw new Error('AuroDatepickerUtilities | validateDateStr: Date must be a string');
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
// Guard Clause: Format should be of type string
|
|
522
|
+
if (typeof format !== "string") {
|
|
523
|
+
throw new Error('AuroDatepickerUtilities | validateDateStr: Format must be a string');
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
// Guard Clause: Length is what we expect it to be
|
|
527
|
+
if (date.length !== dateStrLength) {
|
|
528
|
+
return false;
|
|
529
|
+
}
|
|
530
|
+
// Get a formatted date string and parse it
|
|
531
|
+
const dateParts = dateFormatter.parseDate(date, format);
|
|
532
|
+
|
|
533
|
+
// Guard Clause: Date parse succeeded
|
|
534
|
+
if (!dateParts) {
|
|
535
|
+
return false;
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
// Create the expected date string based on the date parts
|
|
539
|
+
const expectedDateStr = `${dateParts.month}/${dateParts.day || "01"}/${this.getFourDigitYear(dateParts.year)}`;
|
|
540
|
+
|
|
541
|
+
// Generate a date object that we will extract a string date from to compare to the passed in date string
|
|
542
|
+
const dateObj = new Date(this.getFourDigitYear(dateParts.year), dateParts.month - 1, dateParts.day || 1);
|
|
543
|
+
|
|
544
|
+
// Get the date string of the date object we created from the string date
|
|
545
|
+
const actualDateStr = dateFormatter.getDateAsString(dateObj);
|
|
546
|
+
|
|
547
|
+
// Guard Clause: Generated date matches date string input
|
|
548
|
+
if (expectedDateStr !== actualDateStr) {
|
|
549
|
+
return false;
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
// If we passed all other checks, we can assume the date is valid
|
|
553
|
+
return true;
|
|
554
|
+
};
|
|
555
|
+
|
|
556
|
+
/**
|
|
557
|
+
* Determines if a string date value matches the format provided.
|
|
558
|
+
* @param {string} value = The date string value.
|
|
559
|
+
* @param { string} format = The date format to match against.
|
|
560
|
+
* @returns {boolean}
|
|
561
|
+
*/
|
|
562
|
+
this.dateAndFormatMatch = (value, format) => {
|
|
563
|
+
|
|
564
|
+
// Ensure we have both values we need to do the comparison
|
|
565
|
+
if (!value || !format) {
|
|
566
|
+
throw new Error('AuroFormValidation | dateFormatMatch: value and format are required');
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
// If the lengths are different, they cannot match
|
|
570
|
+
if (value.length !== format.length) {
|
|
571
|
+
return false;
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
// Get the parts of the date
|
|
575
|
+
const dateParts = dateFormatter.parseDate(value, format);
|
|
576
|
+
|
|
577
|
+
// Validator for day
|
|
578
|
+
const dayValueIsValid = (day) => {
|
|
579
|
+
|
|
580
|
+
// Guard clause: if there is no day in the dateParts, we can ignore this check.
|
|
581
|
+
if (!dateParts.day) {
|
|
582
|
+
return true;
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
// Guard clause: ensure day exists.
|
|
586
|
+
if (!day) {
|
|
587
|
+
return false;
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
// Convert day to number
|
|
591
|
+
const numDay = Number.parseInt(day, 10);
|
|
592
|
+
|
|
593
|
+
// Guard clause: ensure day is a valid integer
|
|
594
|
+
if (Number.isNaN(numDay)) {
|
|
595
|
+
throw new Error('AuroDatepickerUtilities | dayValueIsValid: Unable to parse day value integer');
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
// Guard clause: ensure day is within the valid range
|
|
599
|
+
if (numDay < this.minDay || numDay > this.maxDay) {
|
|
600
|
+
return false;
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
// Default return
|
|
604
|
+
return true;
|
|
605
|
+
};
|
|
606
|
+
|
|
607
|
+
// Validator for month
|
|
608
|
+
const monthValueIsValid = (month) => {
|
|
609
|
+
|
|
610
|
+
// Guard clause: ensure month exists.
|
|
611
|
+
if (!month) {
|
|
612
|
+
return false;
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
// Convert month to number
|
|
616
|
+
const numMonth = Number.parseInt(month, 10);
|
|
617
|
+
|
|
618
|
+
// Guard clause: ensure month is a valid integer
|
|
619
|
+
if (Number.isNaN(numMonth)) {
|
|
620
|
+
throw new Error('AuroDatepickerUtilities | monthValueIsValid: Unable to parse month value integer');
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
// Guard clause: ensure month is within the valid range
|
|
624
|
+
if (numMonth < this.minMonth || numMonth > this.maxMonth) {
|
|
625
|
+
return false;
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
// Default return
|
|
629
|
+
return true;
|
|
630
|
+
};
|
|
631
|
+
|
|
632
|
+
// Validator for year
|
|
633
|
+
const yearIsValid = (_year) => {
|
|
634
|
+
|
|
635
|
+
// Guard clause: ensure year exists.
|
|
636
|
+
if (!_year) {
|
|
637
|
+
return false;
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
// Get the full year
|
|
641
|
+
const year = this.getFourDigitYear(_year);
|
|
642
|
+
|
|
643
|
+
// Convert year to number
|
|
644
|
+
const numYear = Number.parseInt(year, 10);
|
|
645
|
+
|
|
646
|
+
// Guard clause: ensure year is a valid integer
|
|
647
|
+
if (Number.isNaN(numYear)) {
|
|
648
|
+
throw new Error('AuroDatepickerUtilities | yearValueIsValid: Unable to parse year value integer');
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
// Guard clause: ensure year is within the valid range
|
|
652
|
+
if (numYear < this.minYear || numYear > this.maxYear) {
|
|
653
|
+
return false;
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
// Default return
|
|
657
|
+
return true;
|
|
658
|
+
};
|
|
659
|
+
|
|
660
|
+
// Self-contained checks for month, day, and year
|
|
661
|
+
const checks = [
|
|
662
|
+
monthValueIsValid(dateParts.month),
|
|
663
|
+
dayValueIsValid(dateParts.day),
|
|
664
|
+
yearIsValid(dateParts.year)
|
|
665
|
+
];
|
|
666
|
+
|
|
667
|
+
// If any of the checks failed, the date format does not match and the result is invalid
|
|
668
|
+
const isValid = checks.every((check) => check === true);
|
|
669
|
+
|
|
670
|
+
// If the check is invalid, return false
|
|
671
|
+
if (!isValid) {
|
|
672
|
+
return false;
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
// Default case
|
|
676
|
+
return true;
|
|
677
|
+
};
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
// Export a class instance
|
|
682
|
+
const dateUtilities = new AuroDateUtilities();
|
|
683
|
+
|
|
684
|
+
// Export the class instance methods individually
|
|
685
|
+
const {
|
|
686
|
+
datesMatch,
|
|
687
|
+
validDateStr,
|
|
688
|
+
dateAndFormatMatch,
|
|
689
|
+
minDay,
|
|
690
|
+
minMonth,
|
|
691
|
+
minYear,
|
|
692
|
+
maxDay,
|
|
693
|
+
maxMonth,
|
|
694
|
+
maxYear
|
|
695
|
+
} = dateUtilities;
|
|
696
|
+
|
|
697
|
+
const {
|
|
698
|
+
toNorthAmericanFormat,
|
|
699
|
+
parseDate,
|
|
700
|
+
getDateAsString
|
|
701
|
+
} = dateFormatter;
|
|
702
|
+
|
|
295
703
|
// Copyright (c) Alaska Air. All right reserved. Licensed under the Apache-2.0 license
|
|
296
704
|
// See LICENSE in the project root for license information.
|
|
297
705
|
|
|
298
706
|
|
|
299
707
|
class AuroFormValidation {
|
|
708
|
+
|
|
300
709
|
constructor() {
|
|
301
710
|
this.runtimeUtils = new AuroLibraryRuntimeUtils$1();
|
|
302
711
|
}
|
|
@@ -388,17 +797,17 @@ class AuroFormValidation {
|
|
|
388
797
|
]
|
|
389
798
|
}
|
|
390
799
|
};
|
|
391
|
-
|
|
800
|
+
|
|
392
801
|
let elementType;
|
|
393
802
|
if (this.runtimeUtils.elementMatch(elem, 'auro-input')) {
|
|
394
803
|
elementType = 'input';
|
|
395
804
|
} else if (this.runtimeUtils.elementMatch(elem, 'auro-counter') || this.runtimeUtils.elementMatch(elem, 'auro-counter-group')) {
|
|
396
805
|
elementType = 'counter';
|
|
397
806
|
}
|
|
398
|
-
|
|
807
|
+
|
|
399
808
|
if (elementType) {
|
|
400
809
|
const rules = validationRules[elementType];
|
|
401
|
-
|
|
810
|
+
|
|
402
811
|
if (rules) {
|
|
403
812
|
Object.values(rules).flat().forEach(rule => {
|
|
404
813
|
if (rule.check(elem)) {
|
|
@@ -424,48 +833,82 @@ class AuroFormValidation {
|
|
|
424
833
|
if (!elem.value.match(emailRegex)) {
|
|
425
834
|
elem.validity = 'patternMismatch';
|
|
426
835
|
elem.errorMessage = elem.setCustomValidityForType || elem.setCustomValidity || '';
|
|
836
|
+
return;
|
|
427
837
|
}
|
|
428
838
|
} else if (elem.type === 'credit-card') {
|
|
429
839
|
if (elem.value.length > 0 && elem.value.length < elem.validationCCLength) {
|
|
430
840
|
elem.validity = 'tooShort';
|
|
431
841
|
elem.errorMessage = elem.setCustomValidityForType || elem.setCustomValidity || '';
|
|
842
|
+
return;
|
|
432
843
|
}
|
|
433
844
|
} else if (elem.type === 'number') {
|
|
434
845
|
if (elem.max !== undefined && Number(elem.max) < Number(elem.value)) {
|
|
435
846
|
elem.validity = 'rangeOverflow';
|
|
436
847
|
elem.errorMessage = elem.setCustomValidityRangeOverflow || elem.setCustomValidity || '';
|
|
848
|
+
return;
|
|
437
849
|
}
|
|
438
850
|
|
|
439
851
|
if (elem.min !== undefined && elem.value?.length > 0 && Number(elem.min) > Number(elem.value)) {
|
|
440
852
|
elem.validity = 'rangeUnderflow';
|
|
441
853
|
elem.errorMessage = elem.setCustomValidityRangeUnderflow || elem.setCustomValidity || '';
|
|
854
|
+
return;
|
|
442
855
|
}
|
|
443
|
-
} else if (elem.type === 'date') {
|
|
444
|
-
|
|
856
|
+
} else if (elem.type === 'date' && elem.value?.length > 0) {
|
|
857
|
+
|
|
858
|
+
// Guard Clause: if the value is too short
|
|
859
|
+
if (elem.value.length < elem.lengthForType) {
|
|
860
|
+
|
|
445
861
|
elem.validity = 'tooShort';
|
|
446
862
|
elem.errorMessage = elem.setCustomValidityForType || elem.setCustomValidity || '';
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
863
|
+
return;
|
|
864
|
+
}
|
|
865
|
+
|
|
866
|
+
// Guard Clause: If the value is too long for the type
|
|
867
|
+
if (elem.value?.length > elem.lengthForType) {
|
|
868
|
+
|
|
869
|
+
elem.validity = 'tooLong';
|
|
870
|
+
elem.errorMessage = elem.setCustomValidityForType || elem.setCustomValidity || '';
|
|
871
|
+
return;
|
|
872
|
+
}
|
|
873
|
+
|
|
874
|
+
// Validate that the date passed was the correct format
|
|
875
|
+
if (!dateAndFormatMatch(elem.value, elem.format)) {
|
|
876
|
+
elem.validity = 'patternMismatch';
|
|
877
|
+
elem.errorMessage = elem.setCustomValidityForType || elem.setCustomValidity || 'Invalid Date Format Entered';
|
|
878
|
+
return;
|
|
879
|
+
}
|
|
880
|
+
|
|
881
|
+
// Validate that the date passed was a valid date
|
|
882
|
+
if (!validDateStr(elem.value, elem.format)) {
|
|
883
|
+
elem.validity = 'invalidDate';
|
|
884
|
+
elem.errorMessage = elem.setCustomValidityInvalidDate || elem.setCustomValidity || 'Invalid Date Entered';
|
|
885
|
+
return;
|
|
886
|
+
}
|
|
887
|
+
|
|
888
|
+
// Perform the rest of the validation
|
|
889
|
+
const formattedValue = toNorthAmericanFormat(elem.value, elem.format);
|
|
890
|
+
const valueDate = new Date(formattedValue);
|
|
891
|
+
|
|
892
|
+
// // Validate max date
|
|
893
|
+
if (elem.max?.length === elem.lengthForType) {
|
|
894
|
+
|
|
895
|
+
const maxDate = new Date(toNorthAmericanFormat(elem.max, elem.format));
|
|
896
|
+
|
|
897
|
+
if (valueDate > maxDate) {
|
|
898
|
+
elem.validity = 'rangeOverflow';
|
|
899
|
+
elem.errorMessage = elem.setCustomValidityRangeOverflow || elem.setCustomValidity || '';
|
|
900
|
+
return;
|
|
459
901
|
}
|
|
902
|
+
}
|
|
460
903
|
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
904
|
+
// Validate min date
|
|
905
|
+
if (elem.min?.length === elem.lengthForType) {
|
|
906
|
+
const minDate = new Date(toNorthAmericanFormat(elem.min, elem.format));
|
|
464
907
|
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
908
|
+
if (valueDate < minDate) {
|
|
909
|
+
elem.validity = 'rangeUnderflow';
|
|
910
|
+
elem.errorMessage = elem.setCustomValidityRangeUnderflow || elem.setCustomValidity || '';
|
|
911
|
+
return;
|
|
469
912
|
}
|
|
470
913
|
}
|
|
471
914
|
}
|
|
@@ -584,7 +1027,7 @@ class AuroFormValidation {
|
|
|
584
1027
|
if (input.validationMessage.length > 0) {
|
|
585
1028
|
elem.errorMessage = input.validationMessage;
|
|
586
1029
|
}
|
|
587
|
-
} else if (this.inputElements?.length > 0
|
|
1030
|
+
} else if (this.inputElements?.length > 0 && elem.errorMessage === '') {
|
|
588
1031
|
const firstInput = this.inputElements[0];
|
|
589
1032
|
|
|
590
1033
|
if (firstInput.validationMessage.length > 0) {
|
|
@@ -111,7 +111,7 @@ The use of any Auro custom element has a dependency on the [Auro Design Tokens](
|
|
|
111
111
|
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.
|
|
112
112
|
|
|
113
113
|
```html
|
|
114
|
-
<script type="module" src="https://cdn.jsdelivr.net/npm/@aurodesignsystem/auro-formkit@3.0
|
|
114
|
+
<script type="module" src="https://cdn.jsdelivr.net/npm/@aurodesignsystem/auro-formkit@3.1.0/auro-combobox/+esm"></script>
|
|
115
115
|
```
|
|
116
116
|
<!-- AURO-GENERATED-CONTENT:END -->
|
|
117
117
|
|