Skip to content

Commit

Permalink
fix(timepicker): account for CD before model write (meridian case)
Browse files Browse the repository at this point in the history
Fixes #1696

Closes #1699
  • Loading branch information
pkozlowski-opensource committed Jul 25, 2017
1 parent 78aafac commit ffd86bc
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
32 changes: 32 additions & 0 deletions src/timepicker/timepicker.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,38 @@ describe('ngb-timepicker', () => {
});
}));

it('should work with template-driven form validation when meridian is true', async(() => {
const html = `
<form>
<ngb-timepicker [(ngModel)]="model" name="control"></ngb-timepicker>
</form>`;

const fixture = createTestComponent(html);
const compiled = fixture.nativeElement;
fixture.detectChanges();
fixture.whenStable()
.then(() => {
fixture.detectChanges();
return fixture.whenStable();
})
.then(() => {
expect(getTimepicker(compiled)).toHaveCssClass('ng-valid');
expect(getTimepicker(compiled)).not.toHaveCssClass('ng-invalid');

fixture.componentInstance.model = {hour: 11, minute: 0, second: 0};
fixture.detectChanges();
return fixture.whenStable();
})
.then(() => {
fixture.detectChanges();
return fixture.whenStable();
})
.then(() => {
expect(getTimepicker(compiled)).toHaveCssClass('ng-valid');
expect(getTimepicker(compiled)).not.toHaveCssClass('ng-invalid');
});
}));

it('should work with model-driven form validation', async(() => {
const html = `
<form [formGroup]="form">
Expand Down
2 changes: 1 addition & 1 deletion src/timepicker/timepicker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ const NGB_TIMEPICKER_VALUE_ACCESSOR = {
<div *ngIf="meridian" class="ngb-tp-meridian">
<button type="button" class="btn btn-outline-primary" [ngClass]="setButtonSize()"
[disabled]="disabled" [class.disabled]="disabled"
(click)="toggleMeridian()">{{model.hour >= 12 ? 'PM' : 'AM'}}</button>
(click)="toggleMeridian()">{{model?.hour >= 12 ? 'PM' : 'AM'}}</button>
</div>
</div>
</fieldset>
Expand Down

0 comments on commit ffd86bc

Please sign in to comment.