g00fy- / angular-datepicker

calendar and datepicker directives for angular
MIT License
722 stars 421 forks source link

Update date selected and empty input #310

Open couderA opened 7 years ago

couderA commented 7 years ago

I cannot update the selected date of my datepicker directly in JS.

And I would like to have my input empty rather than having the default set to today.

lanstat commented 7 years ago

Hi, is a problem with the filter "mFormat" and the createMoment function. I solved with this.

Module.filter('mFormat', function () {
    return function (m, format, tz) {
        if (!(moment.isMoment(m))) {
            if (m) {
                return  m;
            } else {
                return '';
            }
        }
        return tz ? moment.tz(m, tz).format(format) : m.format(format);
    };
});

createMoment: function (m) {
      if (tz) {
        return moment.tz(m, tz);
      } else {
          if (/\d\d\/\d\d\/\d\d\d\d/.test(m)) // Test with my format
              return moment(m, 'DD/MM/YYYY');
          else
              return moment.isMoment(m) ? moment.unix(m.unix()) : moment();
      }
    }