@hmcts/rpx-xui-common-lib 1.4.30-date-component-common-validation → 1.4.31-date-component-validation-fixes
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/bundles/hmcts-rpx-xui-common-lib.umd.js +39 -11
- package/bundles/hmcts-rpx-xui-common-lib.umd.js.map +1 -1
- package/bundles/hmcts-rpx-xui-common-lib.umd.min.js +1 -1
- package/bundles/hmcts-rpx-xui-common-lib.umd.min.js.map +1 -1
- package/esm2015/lib/gov-ui/components/gov-uk-date/gov-uk-date.component.js +38 -13
- package/esm5/lib/gov-ui/components/gov-uk-date/gov-uk-date.component.js +42 -12
- package/fesm2015/hmcts-rpx-xui-common-lib.js +35 -12
- package/fesm2015/hmcts-rpx-xui-common-lib.js.map +1 -1
- package/fesm5/hmcts-rpx-xui-common-lib.js +39 -11
- package/fesm5/hmcts-rpx-xui-common-lib.js.map +1 -1
- package/hmcts-rpx-xui-common-lib.metadata.json +1 -1
- package/lib/gov-ui/components/gov-uk-date/gov-uk-date.component.d.ts +2 -0
- package/package.json +1 -1
|
@@ -4556,6 +4556,7 @@
|
|
|
4556
4556
|
* */
|
|
4557
4557
|
var GovUkDateComponent = /** @class */ (function () {
|
|
4558
4558
|
function GovUkDateComponent() {
|
|
4559
|
+
this.isOptional = false;
|
|
4559
4560
|
}
|
|
4560
4561
|
/**
|
|
4561
4562
|
* @return {?}
|
|
@@ -4575,20 +4576,45 @@
|
|
|
4575
4576
|
* @private
|
|
4576
4577
|
* @param {?} d
|
|
4577
4578
|
* @param {?} month
|
|
4579
|
+
* @param {?} year
|
|
4578
4580
|
* @return {?}
|
|
4579
4581
|
*/
|
|
4580
4582
|
GovUkDateComponent.prototype.isValidDate = /**
|
|
4581
4583
|
* @private
|
|
4582
4584
|
* @param {?} d
|
|
4583
4585
|
* @param {?} month
|
|
4586
|
+
* @param {?} year
|
|
4584
4587
|
* @return {?}
|
|
4585
4588
|
*/
|
|
4586
|
-
function (d, month) {
|
|
4589
|
+
function (d, month, year) {
|
|
4587
4590
|
/** @type {?} */
|
|
4588
|
-
var dateCheck =
|
|
4591
|
+
var dateCheck = !isNaN(d.getTime());
|
|
4592
|
+
// Month mismatch occurs if the provided day or month are invalid, or either is omitted. **Note:** This is insufficient for
|
|
4593
|
+
// checking date validity when the year is omitted because it defaults to 1900 - an extra check is required
|
|
4589
4594
|
/** @type {?} */
|
|
4590
|
-
var
|
|
4591
|
-
|
|
4595
|
+
var monthMatch = d.getMonth() === month;
|
|
4596
|
+
/** @type {?} */
|
|
4597
|
+
var yearMatch = d.getFullYear() === year;
|
|
4598
|
+
return dateCheck && monthMatch && yearMatch;
|
|
4599
|
+
};
|
|
4600
|
+
/**
|
|
4601
|
+
* @private
|
|
4602
|
+
* @param {?} value
|
|
4603
|
+
* @return {?}
|
|
4604
|
+
*/
|
|
4605
|
+
GovUkDateComponent.prototype.isEmpty = /**
|
|
4606
|
+
* @private
|
|
4607
|
+
* @param {?} value
|
|
4608
|
+
* @return {?}
|
|
4609
|
+
*/
|
|
4610
|
+
function (value) {
|
|
4611
|
+
// Note: Intentional use of == to check for null or undefined
|
|
4612
|
+
/* eslint-disable eqeqeq */
|
|
4613
|
+
/* tslint:disable:triple-equals */
|
|
4614
|
+
// NaN and < 0 checks required for month field
|
|
4615
|
+
return value == null || value === '' || isNaN(value) || value < 0;
|
|
4616
|
+
/* eslint-enable eqeqeq */
|
|
4617
|
+
/* tslint:enable:triple-equals */
|
|
4592
4618
|
};
|
|
4593
4619
|
/**
|
|
4594
4620
|
* @return {?}
|
|
@@ -4598,8 +4624,7 @@
|
|
|
4598
4624
|
*/
|
|
4599
4625
|
function () {
|
|
4600
4626
|
var _this = this;
|
|
4601
|
-
|
|
4602
|
-
var res = ( /**
|
|
4627
|
+
return ( /**
|
|
4603
4628
|
* @return {?}
|
|
4604
4629
|
*/function () {
|
|
4605
4630
|
/** @type {?} */
|
|
@@ -4608,11 +4633,13 @@
|
|
|
4608
4633
|
var month = _this.formGroup.get(_this.month).value - 1;
|
|
4609
4634
|
/** @type {?} */
|
|
4610
4635
|
var year = _this.formGroup.get(_this.year).value;
|
|
4611
|
-
|
|
4612
|
-
|
|
4613
|
-
|
|
4636
|
+
// Validation should pass if the date field is optional and day, month, and year are all empty
|
|
4637
|
+
if (_this.isOptional && _this.isEmpty(day) && _this.isEmpty(month) && _this.isEmpty(year)) {
|
|
4638
|
+
return null;
|
|
4639
|
+
}
|
|
4640
|
+
// + to coerce year to a number
|
|
4641
|
+
return !_this.isValidDate(new Date(year, month, day), month, +year) ? { dateComponent: true } : null;
|
|
4614
4642
|
});
|
|
4615
|
-
return res;
|
|
4616
4643
|
};
|
|
4617
4644
|
GovUkDateComponent.decorators = [
|
|
4618
4645
|
{ type: i0.Component, args: [{
|
|
@@ -4626,7 +4653,8 @@
|
|
|
4626
4653
|
GovUkDateComponent.propDecorators = {
|
|
4627
4654
|
config: [{ type: i0.Input }],
|
|
4628
4655
|
errorMessage: [{ type: i0.Input }],
|
|
4629
|
-
formGroup: [{ type: i0.Input }]
|
|
4656
|
+
formGroup: [{ type: i0.Input }],
|
|
4657
|
+
isOptional: [{ type: i0.Input }]
|
|
4630
4658
|
};
|
|
4631
4659
|
return GovUkDateComponent;
|
|
4632
4660
|
}());
|