Skip to content

Commit

Permalink
Timepicker: Added showPlaceholders boolean. Ref valor-software#3544
Browse files Browse the repository at this point in the history
  • Loading branch information
TomONeill committed Feb 15, 2018
1 parent 465ed0d commit ca21b40
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 17 deletions.
3 changes: 2 additions & 1 deletion demo/src/app/components/+timepicker/demos/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ export function getTimepickerConfig(): TimepickerConfig {
readonlyInput: false,
mousewheel: true,
showMinutes: true,
showSeconds: false
showSeconds: false,
showPlaceholders: true
});
}

Expand Down
2 changes: 2 additions & 0 deletions demo/src/app/components/+timepicker/demos/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { DemoTimepickerCustomComponent } from './custom/custom';
import { DemoTimepickerDynamicComponent } from './dynamic/dynamic';
import { DemoTimepickerMinMaxComponent } from './min-max/min-max';
import { DemoTimepickerToggleMinutesSecondsComponent } from './toggle-minutes-seconds/toggle-minutes-seconds';
import { DemoTimepickerTogglePlaceholdersComponent } from './toggle-placeholders/toggle-placeholders';
import { DemoTimepickerMousewheelArrowkeysComponent } from './mousewheel-arrowkeys/mousewheel-arrowkeys';
import { DemoTimepickerCustomValidationComponent } from './custom-validation/custom-validation';
import { DemoTimepickerSpinnersComponent } from './spinners/spinners';
Expand All @@ -19,6 +20,7 @@ export const DEMO_COMPONENTS = [
DemoTimepickerCustomComponent,
DemoTimepickerDynamicComponent,
DemoTimepickerToggleMinutesSecondsComponent,
DemoTimepickerTogglePlaceholdersComponent,
DemoTimepickerMousewheelArrowkeysComponent,
DemoTimepickerCustomValidationComponent,
DemoTimepickerSpinnersComponent
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<timepicker [(ngModel)]="myTime" [showPlaceholders]="showPlaceholders"></timepicker>

<pre class="alert alert-info">Time is: {{myTime}}<br>showPlaceholders: {{showPlaceholders}}</pre>

<button class="btn btn-default text-center" (click)="togglePlaceholders()">
{{showPlaceholders? 'Hide placeholders' : 'Show placeholders'}}
</button>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Component } from '@angular/core';

@Component({
selector: 'demo-timepicker-placeholders',
templateUrl: './toggle-placeholders.html'
})
export class DemoTimepickerTogglePlaceholdersComponent {
myTime: Date = new Date();
showPlaceholders: boolean = true;

togglePlaceholders(): void {
this.showPlaceholders = !this.showPlaceholders;
}
}
69 changes: 56 additions & 13 deletions src/spec/timepicker/timepicker.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,12 +292,16 @@ describe('Component: timepicker', () => {
fixture = TestBed.createComponent(TimepickerComponent);
fixture.detectChanges();
component = fixture.componentInstance;
inputMinutes = getInputElements(fixture)[1];
});
it('should hide minutes field when property showMinutes is == false', () => {
component.showMinutes = false;

component.writeValue(testTime());

fixture.detectChanges();
expect(inputSeconds).toBeFalsy();

This comment has been minimized.

Copy link
@TomONeill

TomONeill Feb 15, 2018

Owner

This tested on seconds instead of minutes, which is why I made this change.

inputMinutes = getInputElements(fixture)[1];

expect(inputMinutes).toBeFalsy();
});
});

Expand All @@ -312,33 +316,72 @@ describe('Component: timepicker', () => {

// отображать поле секунды если showSeconds включен
it('should display seconds field if showMeridian switch on', () => {
component.showSeconds = true;

component.writeValue(testTime());

fixture.detectChanges();
fixture.whenStable().then(() => {
inputSeconds = getInputElements(fixture)[2];

fireEvent(inputSeconds, 'change');

expect(inputSeconds).toBeTruthy();
});
});
// проверить данные в поле секунды
it('should validate the data in the seconds input', () => {
component.showSeconds = true;

component.writeValue(testTime());
component.writeValue(testTime(2, 6, 7));

This comment has been minimized.

Copy link
@TomONeill

TomONeill Feb 15, 2018

Owner

Did not make this change. Not sure how it got here.


fixture.detectChanges();
fixture.whenStable().then(() => {
inputSeconds = getInputElements(fixture)[2];

fireEvent(inputSeconds, 'change');

expect(inputSeconds).toBeTruthy();
expect(inputSeconds.value).toBe('07');
});
});
// проверить данные в поле секунды
it('should validate the data in the seconds input', () => {
component.showSeconds = true;
});

component.writeValue(testTime(2, 6, 7));
describe('hide placeholders on inputs with property of showPlaceholders', () => {
beforeEach(() => {
fixture = TestBed.createComponent(TimepickerComponent);
fixture.detectChanges();

component = fixture.componentInstance;
});
it('should show placeholders on inputs when property showPlaceholders is == true', () => {
component.showSeconds = true;
component.showPlaceholders = true;

component.writeValue(testTime());

fixture.detectChanges();
fixture.whenStable().then(() => {
inputSeconds = getInputElements(fixture)[2];
inputHours = getInputElements(fixture)[0];
inputMinutes = getInputElements(fixture)[1];
inputSeconds = getInputElements(fixture)[2];

fireEvent(inputSeconds, 'change');
expect(inputHours.placeholder).not.toBeFalsy();
expect(inputMinutes.placeholder).not.toBeFalsy();
expect(inputSeconds.placeholder).not.toBeFalsy();
});
it('should hide placeholders on inputs when property showPlaceholders is == false', () => {
component.showSeconds = true;
component.showPlaceholders = false;

component.writeValue(testTime());

expect(inputSeconds.value).toBe('07');
});
fixture.detectChanges();
inputHours = getInputElements(fixture)[0];
inputMinutes = getInputElements(fixture)[1];
inputSeconds = getInputElements(fixture)[2];

expect(inputHours.placeholder).toBeFalsy();
expect(inputMinutes.placeholder).toBeFalsy();
expect(inputSeconds.placeholder).toBeFalsy();
});
});

Expand Down
6 changes: 3 additions & 3 deletions src/timepicker/timepicker.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<td class="form-group" [class.has-error]="invalidHours">
<input type="text"
class="form-control text-center bs-timepicker-field"
placeholder="HH"
[attr.placeholder]="showPlaceholders ? 'HH' : null"
maxlength="2"
[readonly]="readonlyInput"
[value]="hours"
Expand All @@ -48,7 +48,7 @@
<td class="form-group" *ngIf="showMinutes"[class.has-error]="invalidMinutes">
<input type="text"
class="form-control text-center bs-timepicker-field"
placeholder="MM"
[attr.placeholder]="showPlaceholders ? 'MM' : null"
maxlength="2"
[readonly]="readonlyInput"
[value]="minutes"
Expand All @@ -64,7 +64,7 @@
[class.has-error]="invalidSeconds">
<input type="text"
class="form-control text-center bs-timepicker-field"
placeholder="SS"
[attr.placeholder]="showPlaceholders ? 'SS' : null"
maxlength="2"
[readonly]="readonlyInput"
[value]="seconds"
Expand Down
2 changes: 2 additions & 0 deletions src/timepicker/timepicker.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ export class TimepickerComponent
@Input() showMinutes: boolean;
/** show seconds in timepicker */
@Input() showSeconds: boolean;
/** show placeholders in timepicker */
@Input() showPlaceholders: boolean;
/** meridian labels based on locale */
@Input() meridians: string[];
/** minimum time user can select */
Expand Down
2 changes: 2 additions & 0 deletions src/timepicker/timepicker.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ export class TimepickerConfig {
showSeconds = false;
/** show minutes in timepicker */
showMinutes = true;
/** show placeholders in timepicker */
showPlaceholders = true;
/** minimum time user can select */
min: Date;
/** maximum time user can select */
Expand Down

0 comments on commit ca21b40

Please sign in to comment.