Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emitting event when datepicker selection is done #733

Merged
merged 2 commits into from
Jul 14, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion components/datepicker/datepicker-inner.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Component, OnInit, EventEmitter, Input, OnChanges} from '@angular/core';
import {Component, OnInit, EventEmitter, Input, OnChanges, Output} from '@angular/core';
import {CORE_DIRECTIVES, NgClass} from '@angular/common';
import {FORM_DIRECTIVES, NgModel} from '@angular/forms';
import {DateFormatter} from './date-formatter';
Expand Down Expand Up @@ -70,6 +70,8 @@ export class DatePickerInnerComponent implements OnInit, OnChanges {
@Input() public dateDisabled:any;
@Input() public initDate:Date;

@Output() public selectionDone: EventEmitter<Date> = new EventEmitter<Date>(undefined);

public stepDay:any = {};
public stepMonth:any = {};
public stepYear:any = {};
Expand Down Expand Up @@ -248,6 +250,7 @@ export class DatePickerInnerComponent implements OnInit, OnChanges {
}

this.activeDate = new Date(date.getFullYear(), date.getMonth(), date.getDate());
this.selectionDone.emit(this.activeDate);
} else {
this.activeDate = date;
this.datepickerMode = this.modes[this.modes.indexOf(this.datepickerMode) - 1];
Expand Down
11 changes: 9 additions & 2 deletions components/datepicker/datepicker.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Component, Self, Input} from '@angular/core';
import {Component, Self, Input, Output, EventEmitter} from '@angular/core';
import {CORE_DIRECTIVES} from '@angular/common';
import {FORM_DIRECTIVES, ControlValueAccessor, NgModel} from '@angular/forms';
import {DatePickerInnerComponent} from './datepicker-inner.component';
Expand Down Expand Up @@ -32,7 +32,8 @@ import {YearPickerComponent} from './yearpicker.component';
[dateDisabled]="dateDisabled"
[templateUrl]="templateUrl"
[onlyCurrentMonth]="onlyCurrentMonth"
[shortcutPropagation]="shortcutPropagation">
[shortcutPropagation]="shortcutPropagation"
(selectionDone)="onSelectionDone($event)">
<daypicker tabindex="0"></daypicker>
<monthpicker tabindex="0"></monthpicker>
<yearpicker tabindex="0"></yearpicker>
Expand Down Expand Up @@ -64,6 +65,8 @@ export class DatePickerComponent implements ControlValueAccessor {
// todo: change type during implementation
@Input() public dateDisabled:any;

@Output() public selectionDone: EventEmitter<Date> = new EventEmitter<Date>(undefined);

public onChange:any = Function.prototype;
public onTouched:any = Function.prototype;

Expand Down Expand Up @@ -91,6 +94,10 @@ export class DatePickerComponent implements ControlValueAccessor {
this.cd.viewToModelUpdate(event);
}

public onSelectionDone(event: Date): void {
this.selectionDone.emit(event);
}

// todo: support null value
public writeValue(value:any):void {
// todo: fix something sends here new date all the time
Expand Down