question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

nb-rangepicker - validation - min/max - ngModel - issue

See original GitHub issue

Issue type

I’m submitting a … (check one with “x”)

  • bug report
  • feature request

Issue description

Current behavior: ERROR Error: Uncaught (in promise): TypeError: date2.getTime is not a function TypeError: date2.getTime is not a function at NbNativeDateService.push…/node_modules/@nebular/theme/components/calendar-kit/services/native-date.service.js.NbNativeDateService.compareDates (native-date.service.js:108)

Expected behavior: Nebular 3 - components - form - datepicker -rangepicker to work with [min] and [max] being set.

Both range and date pickers support all parameters as calendar, so, check NbCalendarComponent for additional info.

Steps to reproduce: https://stackblitz.com/edit/nebular-1281-kmwnav?file=src/app/app.component.ts Using the Validation template replace ‘nb-datepicker’ to ‘nb-rangepicker’ and using [(ngModel)]

Related code:

/*
 * @license
 * Copyright Akveo. All Rights Reserved.
 * Licensed under the MIT License. See License.txt in the project root for license information.
 */

import { Component } from '@angular/core';
import { NbDateService } from '@nebular/theme';


@Component({
  selector: 'nb-datepicker-validation',
  template: `
    <div>
      <input nbInput placeholder="Form Picker" [nbDatepicker]="picker" [(ngModel)]="ngModelDate">
      <nb-rangepicker #picker [min]="min" [max]="max"></nb-rangepicker>
    </div>
  `,
  styles: [`
    :host {
      display: flex;
      justify-content: center;
      align-content: center;
      height: 40rem;
    }

    :host input {
      width: 21.875rem;
    }
  `],
})
export class DatepickerValidationComponent {
  min: Date;
  max: Date;

  ngModelDate = {
    start: new Date(),
    end: new Date(),
  };

  constructor(protected dateService: NbDateService<Date>) {
    this.min = this.dateService.addMonth(this.dateService.today(), -1);
    this.max = this.dateService.addMonth(this.dateService.today(), 1);
  }
}

Other information:

npm, node, OS, Browser

Node v11.6.0, npm 6.9.0
OS: macOS (Mojave)
Browser: Chrome

Angular, Nebular

    "@angular/animations": "^7.2.8",
    "@angular/cdk": "^7.3.3",
    "@angular/common": "^7.2.8",
    "@angular/compiler": "^7.2.8",
    "@angular/core": "^7.2.8",
    "@angular/forms": "^7.2.8",
    "@angular/material": "^7.3.3",
    "@angular/platform-browser": "^7.2.8",
    "@angular/platform-browser-dynamic": "^7.2.8",
    "@angular/router": "^7.2.8",
    "@nebular/theme": "^3.4.2",
    "angular2-chartjs": "^0.5.1",
    "chart.js": "^2.7.3",
    "core-js": "^2.6.3",
    "hammerjs": "^2.0.8",
    "nebular-icons": "^1.1.0",
    "ng2-completer": "^2.0.8",
    "ng2-smart-table": "^1.3.5",
    "ngx-markdown": "^8.0.2",
    "rxjs": "~6.4.0",
    "rxjs-compat": "^6.4.0",
    "tslib": "^1.9.0",
    "zone.js": "^0.8.29"

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:8
  • Comments:8

github_iconTop GitHub Comments

4reactions
DanielNetzeriAmcommented, Feb 3, 2020

managed to workaround it by overriding the comparison method to suit the formControl with the rangePickerDirective in the following manner.

constructor(...) {
    this.dateRangesCtrl.patchValue(this.reportsQuery.getValue().dateRange);

    let isStart = true;
    this.dateService.compareDates = (date1: Date, date2: unknown) => {
      let inputVal: Date;
      if (isStart) {
        inputVal = (date2 as { start: Date; end: Date }).start;
        isStart = false;
      } else {
        inputVal = (date2 as { start: Date; end: Date }).end;
        isStart = true;
      }
      return date1 === inputVal ? 0 : date1 > inputVal ? 1 : -1;
    };

    this.min = this.dateService.createDate(2019, 1, 1);
    this.max = new Date();
}

and in template

        <input nbInput placeholder="Pick Date Range" class="date-picker" [nbDatepicker]="formpicker" [formControl]="dateRangesCtrl" />
        <nb-rangepicker #formpicker [min]="min" [max]="max"></nb-rangepicker>
1reaction
LuisUrrutiacommented, Mar 25, 2020

@zhanghongyublog I have the same problem. FormControl With min and max throw the error “date.clone is not function”

Read more comments on GitHub >

github_iconTop Results From Across the Web

Nebular - Datepicker Angular UI Component - GitHub Pages
NbDatepickerDirective may be validated using min and max dates passed to the datepicker.
Read more >
angular - Set minDate/maxDate dynamically on html datepicker
The issue I have is with the default html datepicker, and I need to use this datepicker and not ngb-datepicker. All the solution...
Read more >
facing issue to add min and max value dynamically for ig-date ...
My issue is when i make change in maxDate dynamically and try to select date using ig-date-picker. it emits events twice 1st time...
Read more >
Datepicker - Angular Material
There are three properties that add date validation to the datepicker input. The first two are the min and max properties. In addition...
Read more >
UNPKG - @nebular/theme
34, min: D;. 35, /**. 36, * Maximum date available in picker. 37, * */. 38, max: D;. 39, /**. 40, * Predicate...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found