Skip to content

Commit

Permalink
Implement custom datepicker for Birth Date field
Browse files Browse the repository at this point in the history
  • Loading branch information
marvac committed Feb 1, 2019
1 parent 50de1bf commit fb19215
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
4 changes: 3 additions & 1 deletion Client/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { HomeComponent } from './components/home/home.component';
import { RegisterComponent } from './components/register/register.component';
import { ErrorInterceptorProvider } from './services/error.interceptor';
import { AlertifyService } from './services/alertify.service';
import { BsDropdownModule, TabsModule } from 'ngx-bootstrap';
import { BsDropdownModule, TabsModule, BsDatepickerModule } from 'ngx-bootstrap';
import { MemberListComponent } from './components/members/member-list/member-list.component';
import { ListsComponent } from './components/lists/lists.component';
import { MessagesComponent } from './components/messages/messages.component';
Expand Down Expand Up @@ -65,6 +65,8 @@ export function tokenGetter() {
}),
TabsModule.forRoot(),
BsDropdownModule.forRoot(),
BsDatepickerModule.forRoot(),

RouterModule.forRoot(appRoutes)
],
providers: [
Expand Down
4 changes: 2 additions & 2 deletions Client/src/app/components/register/register.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ <h2 class="text-center text-primary">Sign Up</h2>

<div class="form-group">
<input [ngClass]="{'is-invalid': registerForm.get('dateOfBirth').errors && registerForm.get('dateOfBirth').touched}" class="form-control"
placeholder="Date of Birth" formControlName="dateOfBirth" type="date">
placeholder="Date of Birth" formControlName="dateOfBirth" type="text" bsDatepicker [bsConfig]="bsConfig">
<div class="invalid-feedback" *ngIf="registerForm.get('dateOfBirth').touched && registerForm.get('dateOfBirth').hasError('required')">Date of Birth is required</div>
</div>

Expand Down Expand Up @@ -69,7 +69,7 @@ <h2 class="text-center text-primary">Sign Up</h2>
</div>

<div class="form-group text-center">
<button class="btn btn-success" type="submit">Register</button>
<button class="btn btn-success" type="submit" [disabled]="!registerForm.valid">Register</button>
<button class="btn btn-default" type="button" (click)="cancel()">Cancel</button>
</div>

Expand Down
6 changes: 6 additions & 0 deletions Client/src/app/components/register/register.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Component, OnInit, Input, EventEmitter, Output } from '@angular/core';
import { AuthService } from 'src/app/services/auth.service';
import { AlertifyService } from 'src/app/services/alertify.service';
import { FormGroup, FormControl, Validators, FormBuilder } from '@angular/forms';
import { BsDatepickerConfig } from 'ngx-bootstrap';

@Component({
selector: 'app-register',
Expand All @@ -13,13 +14,18 @@ export class RegisterComponent implements OnInit {

model: any = {};
registerForm: FormGroup;
bsConfig: Partial<BsDatepickerConfig>;

constructor(
private authService: AuthService,
private alertify: AlertifyService,
private formBuilder: FormBuilder) { }

ngOnInit() {
this.bsConfig = {
containerClass: 'theme-red'
};

this.createRegisterForm();
}

Expand Down
2 changes: 1 addition & 1 deletion Client/src/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
@import '../node_modules/font-awesome/css/font-awesome.min.css';
@import '../node_modules/alertifyjs/build/css/alertify.min.css';
@import '../node_modules/alertifyjs/build/css/themes/bootstrap.min.css';

@import "../node_modules/ngx-bootstrap/datepicker/bs-datepicker.css";

.tab-panel {
border: 1px solid #ddd;
Expand Down

0 comments on commit fb19215

Please sign in to comment.