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

Cancel Button Performing Clear Button Behavior #554

Open
AnnuValand13 opened this issue Sep 20, 2024 · 0 comments
Open

Cancel Button Performing Clear Button Behavior #554

AnnuValand13 opened this issue Sep 20, 2024 · 0 comments

Comments

@AnnuValand13
Copy link

Versions

  • Angular version: 18.2.1
  • component version: 6.0.4

Describe the bug
Clicking the cancel button currently performs the functionality of the clear button.

To Reproduce
Steps to reproduce the behavior:

<ngx-daterangepicker-material [ngClass]="isDatePickerVisible ? 'd-block' : 'd-none'" [opens]="'right'" [showDropdowns]="false" [showCustomRangeLabel]="true" [ranges]="dateRanges" [linkedCalendars]="false" [closeOnAutoApply]="true" [alwaysShowCalendars]="false" [keepCalendarOpeningWithRange]="false" [showRangeLabelOnInput]="true" [showCancel]="true" (rangeClicked)="rangeClicked($event)" (datesUpdated)="choosedDate($event)" (applyDateClick)="applyDateClick()" (cancelClicked)="cancelDateClick($event)" #dateRangePicker> </ngx-daterangepicker-material>

Below is TS code:

`Ts :

  start_date: any;
  end_date: any;
  selected_range: string = '';

  tempStartDate!: string;
  tempEndDate!: string;
  selected: { start: Dayjs; end: Dayjs; } | undefined;
  dateRanges: any = {
    'Today': [moment(), moment()],
    'Yesterday': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
    'Last 7 Days': [moment().subtract(6, 'days'), moment()],
    'Last 30 Days': [moment().subtract(29, 'days'), moment()],
    'This Month': [moment().startOf('month'), moment().endOf('month')],
    'Last Month': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
  };
  dateRangeControl = new FormControl([this.dateRanges['Last 7 Days'][0], this.dateRanges['Last 7 Days'][1]]);
  choosedDate(value: any) {
    this.start_date = value.startDate.format('YYYY-MM-DD');
    this.end_date = value.endDate.format('YYYY-MM-DD');
    this.selected_range = this.start_date + " to " + this.end_date;

    this.getAllUsers(this.currentPage, this.itemsPerPage);
    this.toggleDatePicker();
  }

  toggleDatePicker(): void {
    this.isDatePickerVisible = !this.isDatePickerVisible;
  }

  rangeClicked(range: any): void {
    this.start_date = range.dates[0].format('YYYY-MM-DD');
    this.end_date = range.dates[1].format('YYYY-MM-DD');
    this.selected_range = this.start_date + " to " + this.end_date;
    this.getAllUsers(this.currentPage, this.itemsPerPage);
  }

  datesUpdated(range: any): void {
    this.start_date = range.dates[0].format('YYYY-MM-DD');
    this.end_date = range.dates[1].format('YYYY-MM-DD');
    this.selected_range = this.start_date + " to " + this.end_date;
    this.getAllUsers(this.currentPage, this.itemsPerPage);
    this.toggleDatePicker();
  }

  applyDateClick(): void {
    this.start_date = this.tempStartDate;
    this.end_date = this.tempEndDate;
    this.selected_range = ${this.start_date} to ${this.end_date};
    this.getAllUsers(this.currentPage, this.itemsPerPage);
    this.toggleDatePicker();
  }

  cancelDateClick(range: any): void {
    this.isDatePickerVisible = false;
  }`

Expected behavior
Cancle should only close calender, do not clear selection.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant