Skip to content

[Bugfix]: Fix uninformative error message for incorrect value in Event date field #3648

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<mat-datepicker-toggle matIconSuffix [for]="dp"></mat-datepicker-toggle>
<mat-datepicker #dp></mat-datepicker>

<mat-error *ngIf="startDate.hasError('dateIncorrect')">{{ 'create-event.date-error-format' | translate }}</mat-error>
<mat-error *ngIf="day.hasError('dateIncorrect')">{{ 'create-event.date-error-format' | translate }}</mat-error>
<mat-error *ngIf="startDate.hasError('dateInPast')">{{ 'create-event.date-error' | translate }}</mat-error>
</mat-form-field>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AfterViewInit, Component, ElementRef, Input, OnDestroy, OnInit, ViewChild } from '@angular/core';
import { AfterViewInit, ChangeDetectorRef, Component, ElementRef, Input, OnDestroy, OnInit, ViewChild } from '@angular/core';
import { AbstractControl, FormArray, FormGroup } from '@angular/forms';
import { DateAdapter, MAT_DATE_FORMATS, MAT_DATE_LOCALE } from '@angular/material/core';
import { IMask } from 'angular-imask';
Expand All @@ -7,13 +7,14 @@ import 'moment/locale/uk';
import { LanguageService } from 'src/app/shared/i18n/language.service';
import { MomentDateAdapter } from 'src/app/shared/services/moment-date-adapter';
import { Subject, takeUntil } from 'rxjs';
import { dateFormatValidator } from '../../../validators/event-custom-validators';

export const MY_FORMATS = {
parse: {
dateInput: 'MMM DD, YYYY'
dateInput: ['DD MMM, YYYY', 'DD.MM.YYYY', 'MMM DD, YYYY', 'MM/DD/YYYY']
},
display: {
dateInput: 'MMM DD, YYYY',
dateInput: 'LL',
monthYearLabel: 'MMM YYYY',
dateA11yLabel: 'LL',
monthYearA11yLabel: 'MMMM YYYY'
Expand Down Expand Up @@ -70,7 +71,8 @@ export class DateTimeComponent implements OnInit, AfterViewInit, OnDestroy {
mask = IMask.InputMask<any>;
constructor(
private ls: LanguageService,
private adapter: DateAdapter<any>
private adapter: DateAdapter<any>,
private cdr: ChangeDetectorRef
) {}

get startDate() {
Expand Down Expand Up @@ -129,6 +131,9 @@ export class DateTimeComponent implements OnInit, AfterViewInit, OnDestroy {

// Subscribe to date value changes
this.day.valueChanges.pipe(takeUntil(this.$destroy)).subscribe((newDate) => {
if (!newDate) {
return;
}
const newStartDate = new Date(newDate.toDate());
newStartDate.setHours(this.startDate.value.getHours(), this.startDate.value.getMinutes(), 0, 0);

Expand All @@ -146,6 +151,9 @@ export class DateTimeComponent implements OnInit, AfterViewInit, OnDestroy {
ngAfterViewInit() {
this.startTimeMask = IMask(this.startTimeRef.nativeElement, this.timeMask);
this.endTimeMask = IMask(this.endTimeRef.nativeElement, this.timeMask);
this.day.addValidators(dateFormatValidator());
this.day.updateValueAndValidity();
this.cdr.detectChanges();
}

getDateErrors(date: moment.Moment | null) {
Expand Down

This file was deleted.

Loading
Loading