@aurodesignsystem/auro-formkit 3.1.0-beta.1 → 3.1.0
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 +9 -3
- package/components/checkbox/demo/api.min.js +468 -25
- package/components/checkbox/demo/index.min.js +468 -25
- package/components/checkbox/dist/index.js +468 -25
- package/components/checkbox/dist/registered.js +468 -25
- package/components/combobox/demo/api.md +1 -1
- package/components/combobox/demo/api.min.js +1265 -235
- package/components/combobox/demo/index.min.js +1265 -235
- package/components/combobox/dist/auro-combobox.d.ts +32 -5
- package/components/combobox/dist/index.js +1130 -100
- package/components/combobox/dist/registered.js +1130 -100
- package/components/counter/demo/api.md +1 -1
- package/components/counter/demo/api.min.js +575 -71
- package/components/counter/demo/index.min.js +575 -71
- package/components/counter/dist/auro-counter-group.d.ts +2 -5
- package/components/counter/dist/index.js +575 -71
- package/components/counter/dist/registered.js +575 -71
- package/components/datepicker/demo/api.md +0 -1
- package/components/datepicker/demo/api.min.js +1077 -106
- package/components/datepicker/demo/index.min.js +1077 -106
- package/components/datepicker/dist/auro-datepicker.d.ts +0 -13
- package/components/datepicker/dist/index.js +1077 -106
- package/components/datepicker/dist/registered.js +1077 -106
- package/components/dropdown/demo/api.md +9 -6
- package/components/dropdown/demo/api.min.js +107 -43
- package/components/dropdown/demo/index.md +0 -83
- package/components/dropdown/demo/index.min.js +107 -43
- package/components/dropdown/dist/auro-dropdown.d.ts +30 -12
- package/components/dropdown/dist/index.js +107 -43
- package/components/dropdown/dist/registered.js +107 -43
- 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/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/radio/demo/api.min.js +468 -25
- package/components/radio/demo/index.min.js +468 -25
- package/components/radio/dist/index.js +468 -25
- package/components/radio/dist/registered.js +468 -25
- package/components/select/demo/api.md +1 -1
- package/components/select/demo/api.min.js +575 -71
- package/components/select/demo/index.md +1 -46
- package/components/select/demo/index.min.js +575 -71
- package/components/select/dist/auro-select.d.ts +2 -5
- package/components/select/dist/index.js +575 -71
- package/components/select/dist/registered.js +575 -71
- package/package.json +2 -2
- package/components/form/demo/autocomplete.html +0 -15
|
@@ -3973,6 +3973,414 @@ class AuroInputUtilities {
|
|
|
3973
3973
|
}
|
|
3974
3974
|
}
|
|
3975
3975
|
|
|
3976
|
+
class DateFormatter {
|
|
3977
|
+
|
|
3978
|
+
constructor() {
|
|
3979
|
+
|
|
3980
|
+
/**
|
|
3981
|
+
* @description Parses a date string into its components.
|
|
3982
|
+
* @param {string} dateStr - Date string to parse.
|
|
3983
|
+
* @param {string} format - Date format to parse.
|
|
3984
|
+
* @returns {Object<key["month" | "day" | "year"]: number>|undefined}
|
|
3985
|
+
*/
|
|
3986
|
+
this.parseDate = (dateStr, format = 'mm/dd/yyyy') => {
|
|
3987
|
+
|
|
3988
|
+
// Guard Clause: Date string is defined
|
|
3989
|
+
if (!dateStr) {
|
|
3990
|
+
return undefined;
|
|
3991
|
+
}
|
|
3992
|
+
|
|
3993
|
+
// Assume the separator is a "/" a defined in our code base
|
|
3994
|
+
const separator = '/';
|
|
3995
|
+
|
|
3996
|
+
// Get the parts of the date and format
|
|
3997
|
+
const valueParts = dateStr.split(separator);
|
|
3998
|
+
const formatParts = format.split(separator);
|
|
3999
|
+
|
|
4000
|
+
// Check if the value and format have the correct number of parts
|
|
4001
|
+
if (valueParts.length !== formatParts.length) {
|
|
4002
|
+
throw new Error('AuroDatepickerUtilities | parseDate: Date string and format length do not match');
|
|
4003
|
+
}
|
|
4004
|
+
|
|
4005
|
+
// Holds the result to be returned
|
|
4006
|
+
const result = formatParts.reduce((acc, part, index) => {
|
|
4007
|
+
const value = valueParts[index];
|
|
4008
|
+
|
|
4009
|
+
if ((/m/iu).test(part)) {
|
|
4010
|
+
acc.month = value;
|
|
4011
|
+
} else if ((/d/iu).test(part)) {
|
|
4012
|
+
acc.day = value;
|
|
4013
|
+
} else if ((/y/iu).test(part)) {
|
|
4014
|
+
acc.year = value;
|
|
4015
|
+
}
|
|
4016
|
+
|
|
4017
|
+
return acc;
|
|
4018
|
+
}, {});
|
|
4019
|
+
|
|
4020
|
+
// If we found all the parts, return the result
|
|
4021
|
+
if (result.month && result.year) {
|
|
4022
|
+
return result;
|
|
4023
|
+
}
|
|
4024
|
+
|
|
4025
|
+
// Throw an error to let the dev know we were unable to parse the date string
|
|
4026
|
+
throw new Error('AuroDatepickerUtilities | parseDate: Unable to parse date string');
|
|
4027
|
+
};
|
|
4028
|
+
|
|
4029
|
+
/**
|
|
4030
|
+
* Convert a date object to string format.
|
|
4031
|
+
* @param {Object} date - Date to convert to string.
|
|
4032
|
+
* @returns {Object} Returns the date as a string.
|
|
4033
|
+
*/
|
|
4034
|
+
this.getDateAsString = (date) => date.toLocaleDateString(undefined, {
|
|
4035
|
+
year: "numeric",
|
|
4036
|
+
month: "2-digit",
|
|
4037
|
+
day: "2-digit",
|
|
4038
|
+
});
|
|
4039
|
+
|
|
4040
|
+
/**
|
|
4041
|
+
* Converts a date string to a North American date format.
|
|
4042
|
+
* @param {String} dateStr - Date to validate.
|
|
4043
|
+
* @param {String} format - Date format to validate against.
|
|
4044
|
+
* @returns {Boolean}
|
|
4045
|
+
*/
|
|
4046
|
+
this.toNorthAmericanFormat = (dateStr, format) => {
|
|
4047
|
+
|
|
4048
|
+
if (format === 'mm/dd/yyyy') {
|
|
4049
|
+
return dateStr;
|
|
4050
|
+
}
|
|
4051
|
+
|
|
4052
|
+
const parsedDate = this.parseDate(dateStr, format);
|
|
4053
|
+
|
|
4054
|
+
if (!parsedDate) {
|
|
4055
|
+
throw new Error('AuroDatepickerUtilities | toNorthAmericanFormat: Unable to parse date string');
|
|
4056
|
+
}
|
|
4057
|
+
|
|
4058
|
+
const { month, day, year } = parsedDate;
|
|
4059
|
+
|
|
4060
|
+
const dateParts = [];
|
|
4061
|
+
if (month) {
|
|
4062
|
+
dateParts.push(month);
|
|
4063
|
+
}
|
|
4064
|
+
|
|
4065
|
+
if (day) {
|
|
4066
|
+
dateParts.push(day);
|
|
4067
|
+
}
|
|
4068
|
+
|
|
4069
|
+
if (year) {
|
|
4070
|
+
dateParts.push(year);
|
|
4071
|
+
}
|
|
4072
|
+
|
|
4073
|
+
return dateParts.join('/');
|
|
4074
|
+
};
|
|
4075
|
+
}
|
|
4076
|
+
}
|
|
4077
|
+
const dateFormatter = new DateFormatter();
|
|
4078
|
+
|
|
4079
|
+
// filepath: dateConstraints.mjs
|
|
4080
|
+
const DATE_UTIL_CONSTRAINTS = {
|
|
4081
|
+
maxDay: 31,
|
|
4082
|
+
maxMonth: 12,
|
|
4083
|
+
maxYear: 2400,
|
|
4084
|
+
minDay: 1,
|
|
4085
|
+
minMonth: 1,
|
|
4086
|
+
minYear: 1900,
|
|
4087
|
+
};
|
|
4088
|
+
|
|
4089
|
+
class AuroDateUtilitiesBase {
|
|
4090
|
+
|
|
4091
|
+
/**
|
|
4092
|
+
* @description The maximum day value allowed by the various utilities in this class.
|
|
4093
|
+
* @readonly
|
|
4094
|
+
* @type {Number}
|
|
4095
|
+
*/
|
|
4096
|
+
get maxDay() {
|
|
4097
|
+
return DATE_UTIL_CONSTRAINTS.maxDay;
|
|
4098
|
+
}
|
|
4099
|
+
|
|
4100
|
+
/**
|
|
4101
|
+
* @description The maximum month value allowed by the various utilities in this class.
|
|
4102
|
+
* @readonly
|
|
4103
|
+
* @type {Number}
|
|
4104
|
+
*/
|
|
4105
|
+
get maxMonth() {
|
|
4106
|
+
return DATE_UTIL_CONSTRAINTS.maxMonth;
|
|
4107
|
+
}
|
|
4108
|
+
|
|
4109
|
+
/**
|
|
4110
|
+
* @description The maximum year value allowed by the various utilities in this class.
|
|
4111
|
+
* @readonly
|
|
4112
|
+
* @type {Number}
|
|
4113
|
+
*/
|
|
4114
|
+
get maxYear() {
|
|
4115
|
+
return DATE_UTIL_CONSTRAINTS.maxYear;
|
|
4116
|
+
}
|
|
4117
|
+
|
|
4118
|
+
/**
|
|
4119
|
+
* @description The minimum day value allowed by the various utilities in this class.
|
|
4120
|
+
* @readonly
|
|
4121
|
+
* @type {Number}
|
|
4122
|
+
*/
|
|
4123
|
+
get minDay() {
|
|
4124
|
+
return DATE_UTIL_CONSTRAINTS.minDay;
|
|
4125
|
+
}
|
|
4126
|
+
|
|
4127
|
+
/**
|
|
4128
|
+
* @description The minimum month value allowed by the various utilities in this class.
|
|
4129
|
+
* @readonly
|
|
4130
|
+
* @type {Number}
|
|
4131
|
+
*/
|
|
4132
|
+
get minMonth() {
|
|
4133
|
+
return DATE_UTIL_CONSTRAINTS.minMonth;
|
|
4134
|
+
}
|
|
4135
|
+
|
|
4136
|
+
/**
|
|
4137
|
+
* @description The minimum year value allowed by the various utilities in this class.
|
|
4138
|
+
* @readonly
|
|
4139
|
+
* @type {Number}
|
|
4140
|
+
*/
|
|
4141
|
+
get minYear() {
|
|
4142
|
+
return DATE_UTIL_CONSTRAINTS.minYear;
|
|
4143
|
+
}
|
|
4144
|
+
}
|
|
4145
|
+
|
|
4146
|
+
/* eslint-disable no-magic-numbers */
|
|
4147
|
+
|
|
4148
|
+
class AuroDateUtilities extends AuroDateUtilitiesBase {
|
|
4149
|
+
|
|
4150
|
+
/**
|
|
4151
|
+
* Returns the current century.
|
|
4152
|
+
* @returns {String} The current century.
|
|
4153
|
+
*/
|
|
4154
|
+
getCentury () {
|
|
4155
|
+
return String(new Date().getFullYear()).slice(0, 2);
|
|
4156
|
+
}
|
|
4157
|
+
|
|
4158
|
+
/**
|
|
4159
|
+
* Returns a four digit year.
|
|
4160
|
+
* @param {String} year - The year to convert to four digits.
|
|
4161
|
+
* @returns {String} The four digit year.
|
|
4162
|
+
*/
|
|
4163
|
+
getFourDigitYear (year) {
|
|
4164
|
+
|
|
4165
|
+
const strYear = String(year).trim();
|
|
4166
|
+
return strYear.length <= 2 ? this.getCentury() + strYear : strYear;
|
|
4167
|
+
}
|
|
4168
|
+
|
|
4169
|
+
constructor() {
|
|
4170
|
+
|
|
4171
|
+
super();
|
|
4172
|
+
|
|
4173
|
+
/**
|
|
4174
|
+
* Compares two dates to see if they match.
|
|
4175
|
+
* @param {Object} date1 - First date to compare.
|
|
4176
|
+
* @param {Object} date2 - Second date to compare.
|
|
4177
|
+
* @returns {Boolean} Returns true if the dates match.
|
|
4178
|
+
*/
|
|
4179
|
+
this.datesMatch = (date1, date2) => new Date(date1).getTime() === new Date(date2).getTime();
|
|
4180
|
+
|
|
4181
|
+
/**
|
|
4182
|
+
* Returns true if value passed in is a valid date.
|
|
4183
|
+
* @param {String} date - Date to validate.
|
|
4184
|
+
* @param {String} format - Date format to validate against.
|
|
4185
|
+
* @returns {Boolean}
|
|
4186
|
+
*/
|
|
4187
|
+
this.validDateStr = (date, format) => {
|
|
4188
|
+
|
|
4189
|
+
// The length we expect the date string to be
|
|
4190
|
+
const dateStrLength = format.length;
|
|
4191
|
+
|
|
4192
|
+
// Guard Clause: Date and format are defined
|
|
4193
|
+
if (typeof date === "undefined" || typeof format === "undefined") {
|
|
4194
|
+
throw new Error('AuroDatepickerUtilities | validateDateStr: Date and format are required');
|
|
4195
|
+
}
|
|
4196
|
+
|
|
4197
|
+
// Guard Clause: Date should be of type string
|
|
4198
|
+
if (typeof date !== "string") {
|
|
4199
|
+
throw new Error('AuroDatepickerUtilities | validateDateStr: Date must be a string');
|
|
4200
|
+
}
|
|
4201
|
+
|
|
4202
|
+
// Guard Clause: Format should be of type string
|
|
4203
|
+
if (typeof format !== "string") {
|
|
4204
|
+
throw new Error('AuroDatepickerUtilities | validateDateStr: Format must be a string');
|
|
4205
|
+
}
|
|
4206
|
+
|
|
4207
|
+
// Guard Clause: Length is what we expect it to be
|
|
4208
|
+
if (date.length !== dateStrLength) {
|
|
4209
|
+
return false;
|
|
4210
|
+
}
|
|
4211
|
+
// Get a formatted date string and parse it
|
|
4212
|
+
const dateParts = dateFormatter.parseDate(date, format);
|
|
4213
|
+
|
|
4214
|
+
// Guard Clause: Date parse succeeded
|
|
4215
|
+
if (!dateParts) {
|
|
4216
|
+
return false;
|
|
4217
|
+
}
|
|
4218
|
+
|
|
4219
|
+
// Create the expected date string based on the date parts
|
|
4220
|
+
const expectedDateStr = `${dateParts.month}/${dateParts.day || "01"}/${this.getFourDigitYear(dateParts.year)}`;
|
|
4221
|
+
|
|
4222
|
+
// Generate a date object that we will extract a string date from to compare to the passed in date string
|
|
4223
|
+
const dateObj = new Date(this.getFourDigitYear(dateParts.year), dateParts.month - 1, dateParts.day || 1);
|
|
4224
|
+
|
|
4225
|
+
// Get the date string of the date object we created from the string date
|
|
4226
|
+
const actualDateStr = dateFormatter.getDateAsString(dateObj);
|
|
4227
|
+
|
|
4228
|
+
// Guard Clause: Generated date matches date string input
|
|
4229
|
+
if (expectedDateStr !== actualDateStr) {
|
|
4230
|
+
return false;
|
|
4231
|
+
}
|
|
4232
|
+
|
|
4233
|
+
// If we passed all other checks, we can assume the date is valid
|
|
4234
|
+
return true;
|
|
4235
|
+
};
|
|
4236
|
+
|
|
4237
|
+
/**
|
|
4238
|
+
* Determines if a string date value matches the format provided.
|
|
4239
|
+
* @param {string} value = The date string value.
|
|
4240
|
+
* @param { string} format = The date format to match against.
|
|
4241
|
+
* @returns {boolean}
|
|
4242
|
+
*/
|
|
4243
|
+
this.dateAndFormatMatch = (value, format) => {
|
|
4244
|
+
|
|
4245
|
+
// Ensure we have both values we need to do the comparison
|
|
4246
|
+
if (!value || !format) {
|
|
4247
|
+
throw new Error('AuroFormValidation | dateFormatMatch: value and format are required');
|
|
4248
|
+
}
|
|
4249
|
+
|
|
4250
|
+
// If the lengths are different, they cannot match
|
|
4251
|
+
if (value.length !== format.length) {
|
|
4252
|
+
return false;
|
|
4253
|
+
}
|
|
4254
|
+
|
|
4255
|
+
// Get the parts of the date
|
|
4256
|
+
const dateParts = dateFormatter.parseDate(value, format);
|
|
4257
|
+
|
|
4258
|
+
// Validator for day
|
|
4259
|
+
const dayValueIsValid = (day) => {
|
|
4260
|
+
|
|
4261
|
+
// Guard clause: if there is no day in the dateParts, we can ignore this check.
|
|
4262
|
+
if (!dateParts.day) {
|
|
4263
|
+
return true;
|
|
4264
|
+
}
|
|
4265
|
+
|
|
4266
|
+
// Guard clause: ensure day exists.
|
|
4267
|
+
if (!day) {
|
|
4268
|
+
return false;
|
|
4269
|
+
}
|
|
4270
|
+
|
|
4271
|
+
// Convert day to number
|
|
4272
|
+
const numDay = Number.parseInt(day, 10);
|
|
4273
|
+
|
|
4274
|
+
// Guard clause: ensure day is a valid integer
|
|
4275
|
+
if (Number.isNaN(numDay)) {
|
|
4276
|
+
throw new Error('AuroDatepickerUtilities | dayValueIsValid: Unable to parse day value integer');
|
|
4277
|
+
}
|
|
4278
|
+
|
|
4279
|
+
// Guard clause: ensure day is within the valid range
|
|
4280
|
+
if (numDay < this.minDay || numDay > this.maxDay) {
|
|
4281
|
+
return false;
|
|
4282
|
+
}
|
|
4283
|
+
|
|
4284
|
+
// Default return
|
|
4285
|
+
return true;
|
|
4286
|
+
};
|
|
4287
|
+
|
|
4288
|
+
// Validator for month
|
|
4289
|
+
const monthValueIsValid = (month) => {
|
|
4290
|
+
|
|
4291
|
+
// Guard clause: ensure month exists.
|
|
4292
|
+
if (!month) {
|
|
4293
|
+
return false;
|
|
4294
|
+
}
|
|
4295
|
+
|
|
4296
|
+
// Convert month to number
|
|
4297
|
+
const numMonth = Number.parseInt(month, 10);
|
|
4298
|
+
|
|
4299
|
+
// Guard clause: ensure month is a valid integer
|
|
4300
|
+
if (Number.isNaN(numMonth)) {
|
|
4301
|
+
throw new Error('AuroDatepickerUtilities | monthValueIsValid: Unable to parse month value integer');
|
|
4302
|
+
}
|
|
4303
|
+
|
|
4304
|
+
// Guard clause: ensure month is within the valid range
|
|
4305
|
+
if (numMonth < this.minMonth || numMonth > this.maxMonth) {
|
|
4306
|
+
return false;
|
|
4307
|
+
}
|
|
4308
|
+
|
|
4309
|
+
// Default return
|
|
4310
|
+
return true;
|
|
4311
|
+
};
|
|
4312
|
+
|
|
4313
|
+
// Validator for year
|
|
4314
|
+
const yearIsValid = (_year) => {
|
|
4315
|
+
|
|
4316
|
+
// Guard clause: ensure year exists.
|
|
4317
|
+
if (!_year) {
|
|
4318
|
+
return false;
|
|
4319
|
+
}
|
|
4320
|
+
|
|
4321
|
+
// Get the full year
|
|
4322
|
+
const year = this.getFourDigitYear(_year);
|
|
4323
|
+
|
|
4324
|
+
// Convert year to number
|
|
4325
|
+
const numYear = Number.parseInt(year, 10);
|
|
4326
|
+
|
|
4327
|
+
// Guard clause: ensure year is a valid integer
|
|
4328
|
+
if (Number.isNaN(numYear)) {
|
|
4329
|
+
throw new Error('AuroDatepickerUtilities | yearValueIsValid: Unable to parse year value integer');
|
|
4330
|
+
}
|
|
4331
|
+
|
|
4332
|
+
// Guard clause: ensure year is within the valid range
|
|
4333
|
+
if (numYear < this.minYear || numYear > this.maxYear) {
|
|
4334
|
+
return false;
|
|
4335
|
+
}
|
|
4336
|
+
|
|
4337
|
+
// Default return
|
|
4338
|
+
return true;
|
|
4339
|
+
};
|
|
4340
|
+
|
|
4341
|
+
// Self-contained checks for month, day, and year
|
|
4342
|
+
const checks = [
|
|
4343
|
+
monthValueIsValid(dateParts.month),
|
|
4344
|
+
dayValueIsValid(dateParts.day),
|
|
4345
|
+
yearIsValid(dateParts.year)
|
|
4346
|
+
];
|
|
4347
|
+
|
|
4348
|
+
// If any of the checks failed, the date format does not match and the result is invalid
|
|
4349
|
+
const isValid = checks.every((check) => check === true);
|
|
4350
|
+
|
|
4351
|
+
// If the check is invalid, return false
|
|
4352
|
+
if (!isValid) {
|
|
4353
|
+
return false;
|
|
4354
|
+
}
|
|
4355
|
+
|
|
4356
|
+
// Default case
|
|
4357
|
+
return true;
|
|
4358
|
+
};
|
|
4359
|
+
}
|
|
4360
|
+
}
|
|
4361
|
+
|
|
4362
|
+
// Export a class instance
|
|
4363
|
+
const dateUtilities = new AuroDateUtilities();
|
|
4364
|
+
|
|
4365
|
+
// Export the class instance methods individually
|
|
4366
|
+
const {
|
|
4367
|
+
datesMatch,
|
|
4368
|
+
validDateStr,
|
|
4369
|
+
dateAndFormatMatch,
|
|
4370
|
+
minDay,
|
|
4371
|
+
minMonth,
|
|
4372
|
+
minYear,
|
|
4373
|
+
maxDay,
|
|
4374
|
+
maxMonth,
|
|
4375
|
+
maxYear
|
|
4376
|
+
} = dateUtilities;
|
|
4377
|
+
|
|
4378
|
+
const {
|
|
4379
|
+
toNorthAmericanFormat,
|
|
4380
|
+
parseDate,
|
|
4381
|
+
getDateAsString
|
|
4382
|
+
} = dateFormatter;
|
|
4383
|
+
|
|
3976
4384
|
// Copyright (c) Alaska Air. All right reserved. Licensed under the Apache-2.0 license
|
|
3977
4385
|
// See LICENSE in the project root for license information.
|
|
3978
4386
|
|
|
@@ -4048,6 +4456,7 @@ let AuroLibraryRuntimeUtils$1 = class AuroLibraryRuntimeUtils {
|
|
|
4048
4456
|
|
|
4049
4457
|
|
|
4050
4458
|
class AuroFormValidation {
|
|
4459
|
+
|
|
4051
4460
|
constructor() {
|
|
4052
4461
|
this.runtimeUtils = new AuroLibraryRuntimeUtils$1();
|
|
4053
4462
|
}
|
|
@@ -4139,17 +4548,17 @@ class AuroFormValidation {
|
|
|
4139
4548
|
]
|
|
4140
4549
|
}
|
|
4141
4550
|
};
|
|
4142
|
-
|
|
4551
|
+
|
|
4143
4552
|
let elementType;
|
|
4144
4553
|
if (this.runtimeUtils.elementMatch(elem, 'auro-input')) {
|
|
4145
4554
|
elementType = 'input';
|
|
4146
4555
|
} else if (this.runtimeUtils.elementMatch(elem, 'auro-counter') || this.runtimeUtils.elementMatch(elem, 'auro-counter-group')) {
|
|
4147
4556
|
elementType = 'counter';
|
|
4148
4557
|
}
|
|
4149
|
-
|
|
4558
|
+
|
|
4150
4559
|
if (elementType) {
|
|
4151
4560
|
const rules = validationRules[elementType];
|
|
4152
|
-
|
|
4561
|
+
|
|
4153
4562
|
if (rules) {
|
|
4154
4563
|
Object.values(rules).flat().forEach(rule => {
|
|
4155
4564
|
if (rule.check(elem)) {
|
|
@@ -4175,48 +4584,82 @@ class AuroFormValidation {
|
|
|
4175
4584
|
if (!elem.value.match(emailRegex)) {
|
|
4176
4585
|
elem.validity = 'patternMismatch';
|
|
4177
4586
|
elem.errorMessage = elem.setCustomValidityForType || elem.setCustomValidity || '';
|
|
4587
|
+
return;
|
|
4178
4588
|
}
|
|
4179
4589
|
} else if (elem.type === 'credit-card') {
|
|
4180
4590
|
if (elem.value.length > 0 && elem.value.length < elem.validationCCLength) {
|
|
4181
4591
|
elem.validity = 'tooShort';
|
|
4182
4592
|
elem.errorMessage = elem.setCustomValidityForType || elem.setCustomValidity || '';
|
|
4593
|
+
return;
|
|
4183
4594
|
}
|
|
4184
4595
|
} else if (elem.type === 'number') {
|
|
4185
4596
|
if (elem.max !== undefined && Number(elem.max) < Number(elem.value)) {
|
|
4186
4597
|
elem.validity = 'rangeOverflow';
|
|
4187
4598
|
elem.errorMessage = elem.setCustomValidityRangeOverflow || elem.setCustomValidity || '';
|
|
4599
|
+
return;
|
|
4188
4600
|
}
|
|
4189
4601
|
|
|
4190
4602
|
if (elem.min !== undefined && elem.value?.length > 0 && Number(elem.min) > Number(elem.value)) {
|
|
4191
4603
|
elem.validity = 'rangeUnderflow';
|
|
4192
4604
|
elem.errorMessage = elem.setCustomValidityRangeUnderflow || elem.setCustomValidity || '';
|
|
4605
|
+
return;
|
|
4193
4606
|
}
|
|
4194
|
-
} else if (elem.type === 'date') {
|
|
4195
|
-
|
|
4607
|
+
} else if (elem.type === 'date' && elem.value?.length > 0) {
|
|
4608
|
+
|
|
4609
|
+
// Guard Clause: if the value is too short
|
|
4610
|
+
if (elem.value.length < elem.lengthForType) {
|
|
4611
|
+
|
|
4196
4612
|
elem.validity = 'tooShort';
|
|
4197
4613
|
elem.errorMessage = elem.setCustomValidityForType || elem.setCustomValidity || '';
|
|
4198
|
-
|
|
4199
|
-
|
|
4200
|
-
|
|
4614
|
+
return;
|
|
4615
|
+
}
|
|
4616
|
+
|
|
4617
|
+
// Guard Clause: If the value is too long for the type
|
|
4618
|
+
if (elem.value?.length > elem.lengthForType) {
|
|
4201
4619
|
|
|
4202
|
-
|
|
4203
|
-
|
|
4204
|
-
|
|
4620
|
+
elem.validity = 'tooLong';
|
|
4621
|
+
elem.errorMessage = elem.setCustomValidityForType || elem.setCustomValidity || '';
|
|
4622
|
+
return;
|
|
4623
|
+
}
|
|
4624
|
+
|
|
4625
|
+
// Validate that the date passed was the correct format
|
|
4626
|
+
if (!dateAndFormatMatch(elem.value, elem.format)) {
|
|
4627
|
+
elem.validity = 'patternMismatch';
|
|
4628
|
+
elem.errorMessage = elem.setCustomValidityForType || elem.setCustomValidity || 'Invalid Date Format Entered';
|
|
4629
|
+
return;
|
|
4630
|
+
}
|
|
4631
|
+
|
|
4632
|
+
// Validate that the date passed was a valid date
|
|
4633
|
+
if (!validDateStr(elem.value, elem.format)) {
|
|
4634
|
+
elem.validity = 'invalidDate';
|
|
4635
|
+
elem.errorMessage = elem.setCustomValidityInvalidDate || elem.setCustomValidity || 'Invalid Date Entered';
|
|
4636
|
+
return;
|
|
4637
|
+
}
|
|
4205
4638
|
|
|
4206
|
-
|
|
4207
|
-
|
|
4208
|
-
|
|
4209
|
-
|
|
4639
|
+
// Perform the rest of the validation
|
|
4640
|
+
const formattedValue = toNorthAmericanFormat(elem.value, elem.format);
|
|
4641
|
+
const valueDate = new Date(formattedValue);
|
|
4642
|
+
|
|
4643
|
+
// // Validate max date
|
|
4644
|
+
if (elem.max?.length === elem.lengthForType) {
|
|
4645
|
+
|
|
4646
|
+
const maxDate = new Date(toNorthAmericanFormat(elem.max, elem.format));
|
|
4647
|
+
|
|
4648
|
+
if (valueDate > maxDate) {
|
|
4649
|
+
elem.validity = 'rangeOverflow';
|
|
4650
|
+
elem.errorMessage = elem.setCustomValidityRangeOverflow || elem.setCustomValidity || '';
|
|
4651
|
+
return;
|
|
4210
4652
|
}
|
|
4653
|
+
}
|
|
4211
4654
|
|
|
4212
|
-
|
|
4213
|
-
|
|
4214
|
-
|
|
4655
|
+
// Validate min date
|
|
4656
|
+
if (elem.min?.length === elem.lengthForType) {
|
|
4657
|
+
const minDate = new Date(toNorthAmericanFormat(elem.min, elem.format));
|
|
4215
4658
|
|
|
4216
|
-
|
|
4217
|
-
|
|
4218
|
-
|
|
4219
|
-
|
|
4659
|
+
if (valueDate < minDate) {
|
|
4660
|
+
elem.validity = 'rangeUnderflow';
|
|
4661
|
+
elem.errorMessage = elem.setCustomValidityRangeUnderflow || elem.setCustomValidity || '';
|
|
4662
|
+
return;
|
|
4220
4663
|
}
|
|
4221
4664
|
}
|
|
4222
4665
|
}
|
|
@@ -4335,7 +4778,7 @@ class AuroFormValidation {
|
|
|
4335
4778
|
if (input.validationMessage.length > 0) {
|
|
4336
4779
|
elem.errorMessage = input.validationMessage;
|
|
4337
4780
|
}
|
|
4338
|
-
} else if (this.inputElements?.length > 0
|
|
4781
|
+
} else if (this.inputElements?.length > 0 && elem.errorMessage === '') {
|
|
4339
4782
|
const firstInput = this.inputElements[0];
|
|
4340
4783
|
|
|
4341
4784
|
if (firstInput.validationMessage.length > 0) {
|
|
@@ -4457,6 +4900,33 @@ class BaseInput extends LitElement {
|
|
|
4457
4900
|
static get properties() {
|
|
4458
4901
|
return {
|
|
4459
4902
|
|
|
4903
|
+
/**
|
|
4904
|
+
* The value for the role attribute.
|
|
4905
|
+
*/
|
|
4906
|
+
a11yRole: {
|
|
4907
|
+
type: String,
|
|
4908
|
+
attribute: true,
|
|
4909
|
+
reflect: true
|
|
4910
|
+
},
|
|
4911
|
+
|
|
4912
|
+
/**
|
|
4913
|
+
* The value for the aria-expanded attribute.
|
|
4914
|
+
*/
|
|
4915
|
+
a11yExpanded: {
|
|
4916
|
+
type: Boolean,
|
|
4917
|
+
attribute: true,
|
|
4918
|
+
reflect: true
|
|
4919
|
+
},
|
|
4920
|
+
|
|
4921
|
+
/**
|
|
4922
|
+
* The value for the aria-controls attribute.
|
|
4923
|
+
*/
|
|
4924
|
+
a11yControls: {
|
|
4925
|
+
type: String,
|
|
4926
|
+
attribute: true,
|
|
4927
|
+
reflect: true
|
|
4928
|
+
},
|
|
4929
|
+
|
|
4460
4930
|
/**
|
|
4461
4931
|
* If set, the label will remain fixed in the active position.
|
|
4462
4932
|
*/
|
|
@@ -5098,6 +5568,10 @@ class BaseInput extends LitElement {
|
|
|
5098
5568
|
} else if (this.type === 'number') {
|
|
5099
5569
|
this.inputMode = 'numeric';
|
|
5100
5570
|
}
|
|
5571
|
+
|
|
5572
|
+
if (this.type === "date" && !this.format) {
|
|
5573
|
+
this.format = 'mm/dd/yyyy';
|
|
5574
|
+
}
|
|
5101
5575
|
}
|
|
5102
5576
|
|
|
5103
5577
|
/**
|
|
@@ -6341,6 +6815,7 @@ var helpTextVersion = '1.0.0';
|
|
|
6341
6815
|
|
|
6342
6816
|
// build the component class
|
|
6343
6817
|
class AuroInput extends BaseInput {
|
|
6818
|
+
|
|
6344
6819
|
constructor() {
|
|
6345
6820
|
super();
|
|
6346
6821
|
|
|
@@ -6453,7 +6928,7 @@ class AuroInput extends BaseInput {
|
|
|
6453
6928
|
?required="${this.required}"
|
|
6454
6929
|
?disabled="${this.disabled}"
|
|
6455
6930
|
aria-describedby="${this.uniqueId}"
|
|
6456
|
-
aria-invalid="${this.validity !== 'valid'}"
|
|
6931
|
+
?aria-invalid="${this.validity !== 'valid'}"
|
|
6457
6932
|
placeholder=${this.getPlaceholder()}
|
|
6458
6933
|
lang="${ifDefined(this.lang)}"
|
|
6459
6934
|
?activeLabel="${this.activeLabel}"
|
|
@@ -6462,7 +6937,10 @@ class AuroInput extends BaseInput {
|
|
|
6462
6937
|
autocapitalize="${ifDefined(this.autocapitalize ? this.autocapitalize : undefined)}"
|
|
6463
6938
|
autocomplete="${ifDefined(this.autocomplete ? this.autocomplete : undefined)}"
|
|
6464
6939
|
part="input"
|
|
6465
|
-
|
|
6940
|
+
role="${ifDefined(this.a11yRole)}"
|
|
6941
|
+
aria-expanded="${ifDefined(this.a11yExpanded)}"
|
|
6942
|
+
aria-controls="${ifDefined(this.a11yControls)}"
|
|
6943
|
+
/>
|
|
6466
6944
|
</div>
|
|
6467
6945
|
<div
|
|
6468
6946
|
class="notificationIcons"
|