Skip to content

Commit

Permalink
fix(timepicker): fix custom validation demo
Browse files Browse the repository at this point in the history
  • Loading branch information
IlyaSurmay committed Jul 6, 2017
1 parent 099f55c commit f2a47df
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
<p>Illustrates custom validation, you have to select time between 11:00 and 12:59</p>

<div class="form-group" [class.has-success]="ctrl.valid" [class.has-danger]="!ctrl.valid">
<div class="form-group">
<timepicker [(ngModel)]="myTime" [formControl]="ctrl" required></timepicker>
</div>

<pre class="alert alert-info">Time is: {{myTime}}</pre>
<pre class="alert"
[class.alert-danger]="!ctrl.valid && !ctrl.pristine"
[class.alert-success]="ctrl.valid && !ctrl.pristine">
Time is: {{myTime}}
</pre>
<div class="alert alert-danger" *ngIf="ctrl.errors?.outOfRange">Invalid time</div>
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,16 @@ export class DemoTimepickerCustomValidationComponent {

public ctrl = new FormControl('', (control: FormControl) => {
const value = control.value;
console.log('control', control);
return control;
if (!value) {
return null;
}
if (value) {
const hours = value.getHours();
if (hours < 11 || hours > 12) {
return {outOfRange: true};
}
}

return null;
});
}

0 comments on commit f2a47df

Please sign in to comment.