Skip to content
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

Enable form field level touched property when control is touched. #277

Open
wants to merge 2 commits into
base: master
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,6 +7,7 @@
[max]="maxHour"
[timeUnit]="timeUnit.HOUR"
[disabled]="disabled"
(onTouched)="onTouched()"
[isDefaultTimeSet]="isDefaultTime"
(timeChanged)="changeHour($event)"></ngx-timepicker-time-control>
<span class="ngx-timepicker__time-colon ngx-timepicker__control--second">:</span>
Expand All @@ -19,11 +20,13 @@
[timeUnit]="timeUnit.MINUTE"
[disabled]="disabled"
[isDefaultTimeSet]="isDefaultTime"
(onTouched)="onTouched()"
(timeChanged)="changeMinute($event)"></ngx-timepicker-time-control>
<ngx-timepicker-period-selector
class="ngx-timepicker__control--forth"
[selectedPeriod]="period$|async"
[disabled]="disabled"
(onTouched)="onTouched()"
(periodSelected)="changePeriod($event)"
*ngIf="format !== 24"></ngx-timepicker-period-selector>
<ngx-material-timepicker-toggle
Expand All @@ -44,6 +47,7 @@
[format]="format"
[cancelBtnTmpl]="cancelBtnTmpl"
[confirmBtnTmpl]="confirmBtnTmpl"
(closed)="onTouched()"
(timeSet)="onTimeSet($event)" #timepicker></ngx-material-timepicker>

<ng-template #defaultIcon>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ export class NgxTimepickerFieldComponent implements OnInit, OnDestroy, ControlVa
private onChange: (value: string) => void = () => {
}

private onTouched: () => void = () => {}

constructor(private timepickerService: NgxMaterialTimepickerService,
@Inject(TIME_LOCALE) private locale: string) {
}
Expand All @@ -112,6 +114,7 @@ export class NgxTimepickerFieldComponent implements OnInit, OnDestroy, ControlVa
}

registerOnTouched(fn: any): void {
this.onTouched = fn;
}

registerOnChange(fn: any): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export class NgxTimepickerPeriodSelectorComponent {
}

@Output() periodSelected = new EventEmitter<TimePeriod>();
@Output() onTouched = new EventEmitter();

period = TimePeriod;
meridiems = Info.meridiems({locale: this.locale});
Expand All @@ -51,10 +52,11 @@ export class NgxTimepickerPeriodSelectorComponent {

select(period: TimePeriod): void {
this.periodSelected.next(period);
this.isOpened = false;
this.backdropClick();
}

backdropClick(): void {
this.isOpened = false;
this.onTouched.emit();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export class NgxTimepickerTimeControlComponent implements OnChanges {
@Input() isDefaultTimeSet: boolean;

@Output() timeChanged = new EventEmitter<number>();
@Output() onTouched = new EventEmitter();

isFocused: boolean;

Expand Down Expand Up @@ -90,7 +91,7 @@ export class NgxTimepickerTimeControlComponent implements OnChanges {

onBlur(): void {
this.isFocused = false;

this.onTouched.emit();
if (this.previousTime !== this.time) {
this.changeTimeIfValid(+this.time);
}
Expand Down