Skip to content

Commit

Permalink
feat(timepicker): disabling meridian and hiding spinners if input is …
Browse files Browse the repository at this point in the history
…disabled (#768)

fixes #759
  • Loading branch information
Adrian Faciu authored and valorkin committed Jul 24, 2016
1 parent 1356ff7 commit a19c841
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
10 changes: 7 additions & 3 deletions components/timepicker/timepicker.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function addMinutes(date:any, minutes:number):Date {
template: `
<table>
<tbody>
<tr class="text-center" [ngClass]="{hidden: !showSpinners}">
<tr class="text-center" [ngClass]="{hidden: !showSpinners || readonlyInput}">
<td><a (click)="incrementHours()" [ngClass]="{disabled: noIncrementHours()}" class="btn btn-link"><span class="glyphicon glyphicon-chevron-up"></span></a></td>
<td>&nbsp;</td>
<td><a (click)="incrementMinutes()" [ngClass]="{disabled: noIncrementMinutes()}" class="btn btn-link"><span class="glyphicon glyphicon-chevron-up"></span></a></td>
Expand All @@ -71,9 +71,9 @@ function addMinutes(date:any, minutes:number):Date {
<td class="form-group" [ngClass]="{'has-error': invalidMinutes}">
<input style="width:50px;" type="text" [(ngModel)]="minutes" (change)="updateMinutes()" class="form-control text-center" [readonly]="readonlyInput" (blur)="minutesOnBlur($event)" maxlength="2">
</td>
<td [ngClass]="{hidden: !showMeridian}" *ngIf="showMeridian"><button type="button" [ngClass]="{disabled: noToggleMeridian()}" class="btn btn-default text-center" (click)="toggleMeridian()">{{meridian}}</button></td>
<td [ngClass]="{hidden: !showMeridian}" *ngIf="showMeridian"><button type="button" [ngClass]="{disabled: noToggleMeridian() || readonlyInput}" class="btn btn-default text-center" (click)="toggleMeridian()">{{meridian}}</button></td>
</tr>
<tr class="text-center" [ngClass]="{hidden: !showSpinners}">
<tr class="text-center" [ngClass]="{hidden: !showSpinners || readonlyInput}">
<td><a (click)="decrementHours()" [ngClass]="{disabled: noDecrementHours()}" class="btn btn-link"><span class="glyphicon glyphicon-chevron-down"></span></a></td>
<td>&nbsp;</td>
<td><a (click)="decrementMinutes()" [ngClass]="{disabled: noDecrementMinutes()}" class="btn btn-link"><span class="glyphicon glyphicon-chevron-down"></span></a></td>
Expand Down Expand Up @@ -389,6 +389,10 @@ export class TimepickerComponent implements ControlValueAccessor, OnInit {
}

private noToggleMeridian():boolean {
if (this.readonlyInput) {
return true;
}

if (this.selected.getHours() < 13) {
return addMinutes(this.selected, 12 * 60) > this.max;
} else {
Expand Down
5 changes: 4 additions & 1 deletion demo/components/timepicker/timepicker-demo.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<timepicker [(ngModel)]="mytime" (change)="changed()" [hourStep]="hstep" [minuteStep]="mstep" [showMeridian]="ismeridian"></timepicker>
<timepicker [(ngModel)]="mytime" (change)="changed()" [hourStep]="hstep"
[minuteStep]="mstep" [showMeridian]="ismeridian"
[readonlyInput]="!isEnabled"></timepicker>

<pre class="alert alert-info">Time is: {{mytime}}</pre>

Expand All @@ -20,5 +22,6 @@
<hr>

<button type="button" class="btn btn-info" (click)="toggleMode()">12H / 24H</button>
<button type="button" class="btn btn-info" (click)="isEnabled=!isEnabled">Enable / Disable input</button>
<button type="button" class="btn btn-primary" (click)="update()">Set to 14:00</button>
<button type="button" class="btn btn-danger" (click)="clear()">Clear</button>
1 change: 1 addition & 0 deletions demo/components/timepicker/timepicker-demo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export class TimepickerDemoComponent {
public hstep:number = 1;
public mstep:number = 15;
public ismeridian:boolean = true;
public isEnabled:boolean = true;

public mytime:Date = new Date();
public options:any = {
Expand Down

0 comments on commit a19c841

Please sign in to comment.