diff --git a/lib/content-services/search/components/search-date-range/search-date-range.component.ts b/lib/content-services/search/components/search-date-range/search-date-range.component.ts index 5254b20d52..a78fa58841 100644 --- a/lib/content-services/search/components/search-date-range/search-date-range.component.ts +++ b/lib/content-services/search/components/search-date-range/search-date-range.component.ts @@ -61,14 +61,14 @@ export class SearchDateRangeComponent implements SearchWidget, OnInit { } getFromValidationMessage(): string { - return this.from.hasError('matDatepickerParse') ? 'SEARCH.FILTER.VALIDATION.INVALID-DATE' : + return this.from.hasError('invalidOnChange') || this.hasParseError(this.from) ? 'SEARCH.FILTER.VALIDATION.INVALID-DATE' : this.from.hasError('matDatepickerMax') ? 'SEARCH.FILTER.VALIDATION.BEYOND-MAX-DATE' : this.from.hasError('required') ? 'SEARCH.FILTER.VALIDATION.REQUIRED-VALUE' : ''; } getToValidationMessage(): string { - return this.to.hasError('matDatepickerParse') ? 'SEARCH.FILTER.VALIDATION.INVALID-DATE' : + return this.to.hasError('invalidOnChange') || this.hasParseError(this.to) ? 'SEARCH.FILTER.VALIDATION.INVALID-DATE' : this.to.hasError('matDatepickerMin') ? 'SEARCH.FILTER.VALIDATION.NO-DAYS' : this.to.hasError('matDatepickerMax') ? 'SEARCH.FILTER.VALIDATION.BEYOND-MAX-DATE' : this.to.hasError('required') ? 'SEARCH.FILTER.VALIDATION.REQUIRED-VALUE' : @@ -125,15 +125,17 @@ export class SearchDateRangeComponent implements SearchWidget, OnInit { onChangedHandler(event: any, formControl: FormControl) { const inputValue = event.srcElement.value; - if (inputValue) { - const formatDate = this.dateAdapter.parse(inputValue, this.datePickerDateFormat); - if (formatDate && formatDate.isValid()) { - formControl.setValue(formatDate); - } else { - formControl.setErrors({ - 'matDatepickerParse': true - }); - } + const formatDate = this.dateAdapter.parse(inputValue, this.datePickerDateFormat); + if (formatDate && formatDate.isValid()) { + formControl.setValue(formatDate); + } else if (formatDate) { + formControl.setErrors({ + 'invalidOnChange': true + }); + } else { + formControl.setErrors({ + 'required': true + }); } } @@ -142,6 +144,10 @@ export class SearchDateRangeComponent implements SearchWidget, OnInit { moment.locale(locale); } + hasParseError(formControl) { + return formControl.hasError('matDatepickerParse') && formControl.getError('matDatepickerParse').text; + } + forcePlaceholder(event: any) { event.srcElement.click(); }