[ADF-3511] The error message for "Created date" fields is not the correct one when are no inputs - fix (#3742)

This commit is contained in:
Suzana Dirla
2018-09-07 12:05:13 +03:00
committed by Eugenio Romano
parent e4da44fd46
commit 931181dee0

View File

@@ -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,23 +125,29 @@ 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 if (formatDate) {
formControl.setErrors({
'invalidOnChange': true
});
} else {
formControl.setErrors({
'matDatepickerParse': true
'required': true
});
}
}
}
setLocale(locale) {
this.dateAdapter.setLocale(locale);
moment.locale(locale);
}
hasParseError(formControl) {
return formControl.hasError('matDatepickerParse') && formControl.getError('matDatepickerParse').text;
}
forcePlaceholder(event: any) {
event.srcElement.click();
}