[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 { 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('matDatepickerMax') ? 'SEARCH.FILTER.VALIDATION.BEYOND-MAX-DATE' :
this.from.hasError('required') ? 'SEARCH.FILTER.VALIDATION.REQUIRED-VALUE' : this.from.hasError('required') ? 'SEARCH.FILTER.VALIDATION.REQUIRED-VALUE' :
''; '';
} }
getToValidationMessage(): string { 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('matDatepickerMin') ? 'SEARCH.FILTER.VALIDATION.NO-DAYS' :
this.to.hasError('matDatepickerMax') ? 'SEARCH.FILTER.VALIDATION.BEYOND-MAX-DATE' : this.to.hasError('matDatepickerMax') ? 'SEARCH.FILTER.VALIDATION.BEYOND-MAX-DATE' :
this.to.hasError('required') ? 'SEARCH.FILTER.VALIDATION.REQUIRED-VALUE' : this.to.hasError('required') ? 'SEARCH.FILTER.VALIDATION.REQUIRED-VALUE' :
@@ -125,15 +125,17 @@ export class SearchDateRangeComponent implements SearchWidget, OnInit {
onChangedHandler(event: any, formControl: FormControl) { onChangedHandler(event: any, formControl: FormControl) {
const inputValue = event.srcElement.value; const inputValue = event.srcElement.value;
if (inputValue) { const formatDate = this.dateAdapter.parse(inputValue, this.datePickerDateFormat);
const formatDate = this.dateAdapter.parse(inputValue, this.datePickerDateFormat); if (formatDate && formatDate.isValid()) {
if (formatDate && formatDate.isValid()) { formControl.setValue(formatDate);
formControl.setValue(formatDate); } else if (formatDate) {
} else { formControl.setErrors({
formControl.setErrors({ 'invalidOnChange': true
'matDatepickerParse': true });
}); } else {
} formControl.setErrors({
'required': true
});
} }
} }
@@ -142,6 +144,10 @@ export class SearchDateRangeComponent implements SearchWidget, OnInit {
moment.locale(locale); moment.locale(locale);
} }
hasParseError(formControl) {
return formControl.hasError('matDatepickerParse') && formControl.getError('matDatepickerParse').text;
}
forcePlaceholder(event: any) { forcePlaceholder(event: any) {
event.srcElement.click(); event.srcElement.click();
} }