Twipped / Kalendae

A javascript date picker that just works.
MIT License
1.99k stars 285 forks source link

Updated the setSelected function to reset viewStartDate on redraw #85

Closed hazanjon closed 11 years ago

hazanjon commented 11 years ago

If you call setSelected and set the draw parameter to false (Forces a redraw) the viewStartDate value will be updated the the first of the input dates.

This should fix Issues: #57 & #77

tagliala commented 11 years ago

@hazanjon thanks for this pull request and for fixing this issue.

Unfortunately I can't automatically merge this one 'cause you worked on the build folder instead of the src one.

Don't worry about this pull request, I did it by myself.

Next time please edit the proper file in the src folder (main.js in this case).

tagliala commented 11 years ago

@hazanjon unfortunately this pull request is breaking something.

Without a proper test suite, it's hard to spot issues

We can't use it.

Check the provided index.html at example:

So is the one on this input.
<input type="text" class="auto-kal">

The popup calendar will show a wrong date (January 0001). I need further investigation

Twipped commented 11 years ago

The problem was that it wasn't checking to make sure the first date actually existed, so setSelected() resulted in a date at 1/1/0001.

I believe I've solved this issue, can you verify, @tagliala?

tagliala commented 11 years ago

i'm trying this way

kal = new Kalendae({
  attachTo:document.body,
  months:1,
});

var newDate = '2013-02-21';
kal.setSelected(newDate);
kal.viewStartDate = newDate;
kal.draw();

I'm still getting when clicking on directions

Uncaught TypeError: Object 2013-02-21 has no method 'subtract' kalendae.standalone.js:169
Uncaught TypeError: Object 2013-02-21 has no method 'add' kalendae.standalone.js:161
Uncaught TypeError: Object 2013-02-21 has no method 'subtract' 

after the call to draw

Twipped commented 11 years ago

That's because viewStartDate has to be a moment object. You're setting it to a string.

tagliala commented 11 years ago

Got that example from issue #77

var newDate = Kalendae.moment('2013-02-21');
kal.setSelected(newDate);
kal.viewStartDate = newDate;
kal.draw();

This is ok. We can close #77 and #57 and update the changelog