angular-datepicker icon indicating copy to clipboard operation
angular-datepicker copied to clipboard

date-picker returns empty string if min-date is defined (which does not work either)

Open arti040 opened this issue 8 years ago • 4 comments

My variables definded in Controller:

  this.scheduleDate = {};
  this.today =  new Date();

My template:

<div
      date-picker
      ng-model = "$ctrl.scheduleDate"
      min-date = "$ctrl.today"
      view = "date"
      min-view = "date"
      max-view = "date"
    ></div>

And when I select a day from date-picker, I got " " in return. I'm using Angular 1.5. Date-picker is inside component, if it matters.

arti040 avatar Apr 20 '16 11:04 arti040

I found this out today. The only thing you can put into min-date and max-date is the name of a variable that exists in $scope. Apparently this control does not support angular expressions...

davidda avatar May 04 '16 16:05 davidda

OK, I am putting the variable name, which gets interpreted correctly on screen, but, for some reason, min-date doesn't work (the field doesn't got invalid). Debugging the code, here's what I found out: Inside the angular-datepicker.js file, this funcion:

function setMin(date) { minDate = date; attrs.minDate = date ? date.format() : date; minValid = moment.isMoment(date); }

Is receiving 'false' as the date value. On my html, I'm passing min-date as:

<input type="datetime" name="date" class="form-control" data-container="body" date-time ng-model="newUser.date" view="date" auto-close="true" min-date = "{{todayDate}}" required min-view="date" format="DD-MM-YYYY">

And, in my controller, I define todayDate as:

$scope.todayDate = new Date();

I also tried filtering the variable in html as:

min-date = "{{todayDate | date:'yyyy-MM-dd' }}"

But it gives me the same result.

eliseguimaraes avatar Sep 05 '16 14:09 eliseguimaraes

My memory on that matter isn't exactly fresh, but from what I've written above you would need to write <input ... min-date = "todayDate" ...> without the curly braces.

davidda avatar Dec 27 '16 15:12 davidda

I have no idea why I hadn't tried that before, but it worked! Thanks @davidda !! It only worked using moment.js (in case anyone bumps into this in the future).

eliseguimaraes avatar Dec 28 '16 22:12 eliseguimaraes