Skip to content

Commit

Permalink
Adds additional event in the lifecycle for more selection feedback an…
Browse files Browse the repository at this point in the history
…d options
  • Loading branch information
butterknight authored and fetrarij committed Jul 27, 2018
1 parent 962d2c1 commit 28fdb7d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,4 +152,8 @@ ranges: any = {

>Fired when clicked on range, and send an object with range label and dates value, eg: `{label: 'This Month', dates: [Moment, Moment]}`
### \(datesUpdated)

>Fires when any date selection occurs, like when selecting days, ranges, or when applying or cancelling changes, and sends an object containing start and end dates, eg: `{startDate: Moment, endDate: Moment}`
## [License](https://github.com/fetrarij/ngx-daterangepicker-material/blob/master/LICENSE)
11 changes: 11 additions & 0 deletions src/daterangepicker/daterangepicker.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,15 @@ export class DaterangepickerComponent implements OnInit {
options: any = {} ; // should get some opt from user
@Output('choosedDate') choosedDate: EventEmitter<Object>;
@Output('rangeClicked') rangeClicked: EventEmitter<Object>;
@Output('datesUpdated') datesUpdated: EventEmitter<Object>;
@ViewChild('pickerContainer') pickerContainer: ElementRef;

constructor(
private el: ElementRef,
) {
this.choosedDate = new EventEmitter();
this.rangeClicked = new EventEmitter();
this.datesUpdated = new EventEmitter();
this.updateMonthsInView();
}

Expand Down Expand Up @@ -402,6 +404,8 @@ export class DaterangepickerComponent implements OnInit {
}

this.updateMonthsInView();
this.datesUpdated.emit({startDate: this.startDate, endDate: this.endDate});

}

setEndDate(endDate) {
Expand Down Expand Up @@ -433,6 +437,7 @@ export class DaterangepickerComponent implements OnInit {
// this.updateElement();
}
this.updateMonthsInView();
this.datesUpdated.emit({startDate: this.startDate, endDate: this.endDate});
}

isInvalidDate(date) {
Expand Down Expand Up @@ -538,12 +543,15 @@ export class DaterangepickerComponent implements OnInit {
if (this.chosenLabel) {
this.choosedDate.emit({chosenLabel: this.chosenLabel, startDate: this.startDate, endDate: this.endDate});
}

this.datesUpdated.emit({startDate: this.startDate, endDate: this.endDate});
this.hide();
}

clickCancel(e) {
this.startDate = this._old.start;
this.endDate = this._old.end;
this.datesUpdated.emit({startDate: this.startDate, endDate: this.endDate});
this.hide();
}
/**
Expand Down Expand Up @@ -712,6 +720,8 @@ export class DaterangepickerComponent implements OnInit {
this.isShown = false; // hide calendars
}
this.rangeClicked.emit({label: label, dates: dates});
this.datesUpdated.emit({startDate: this.startDate, endDate: this.endDate});

this.clickApply();
}
};
Expand Down Expand Up @@ -775,6 +785,7 @@ export class DaterangepickerComponent implements OnInit {
this.startDate = moment().startOf('day');
this.endDate = moment().endOf('day');
this.choosedDate.emit({chosenLabel: '', startDate: null, endDate: null});
this.datesUpdated.emit({startDate: null, endDate: null});
this.hide();
}

Expand Down
4 changes: 4 additions & 0 deletions src/daterangepicker/daterangepicker.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ export class DaterangepickerDirective implements OnInit, OnChanges, DoCheck {
}
@Output('change') onChange: EventEmitter<Object> = new EventEmitter();
@Output('rangeClicked') rangeClicked: EventEmitter<Object> = new EventEmitter();
@Output('datesUpdated') datesUpdated: EventEmitter<Object> = new EventEmitter();

constructor(
public viewContainerRef: ViewContainerRef,
Expand All @@ -145,6 +146,9 @@ export class DaterangepickerDirective implements OnInit, OnChanges, DoCheck {
this.picker.rangeClicked.asObservable().subscribe((range: any) => {
this.rangeClicked.emit(range);
});
this.picker.datesUpdated.asObservable().subscribe((range: any) => {
this.datesUpdated.emit(range);
});
this.picker.choosedDate.asObservable().subscribe((change: any) => {
if (change) {
const value = {};
Expand Down

0 comments on commit 28fdb7d

Please sign in to comment.