soulim / ember-cli-bootstrap-datepicker

Datepicker component for Ember CLI
http://sul.im/ember-cli-bootstrap-datepicker
MIT License
67 stars 57 forks source link

Allow costum value parsing #61

Closed lazybensch closed 8 years ago

lazybensch commented 9 years ago

This PR is related to #58. we too need the input value for our datepicker to sometimes be something else then a date. But I understand that using the Date constructor internally is unreliable. With this PR I simply introduce an API for the user to plug in a custom parser for the date string. This way anyone can decide by him/herself how to process the dates for a particular picker.

to solve @maladon's issue, he now could do:

{{bootstrap-datepicker value=expiresAt customParser=(action myParser)}}

and inside his code:

actions: {
  myParser(value) {
    return new Date(value);
  }
}

The responsibility for how to parse is now in user land. If you want to, you could do fancy stuff with moment.js or other libraries not available from inside bootstrap-datepicker

et commented 9 years ago

This would we be sweet since I've been doing this with an observer

onDatePickerValueChanged: Ember.observer('datePickerValue', function() {
})

which isn't the cleanest.

lazybensch commented 8 years ago

@soulim any thoughts on this? should i rebase or you wanna discuss/close this PR?

soulim commented 8 years ago

I'm sorry for delay @lazybensch. Your idea and PR looks great! :+1: Could you please rebase the branch? I'll be happy to merge it as soon as you finish with rebase.

Thank you! :heart:

lazybensch commented 8 years ago

no worries @soulim. rebased the branch. CI is broken (on master though). looks mergable to me.

soulim commented 8 years ago

Thank a lot! Don't worry about CI. It has nothing to your PR.

soulim commented 8 years ago

Wish you a wonderful day! :smile:

jelhan commented 8 years ago

@lazybensch @soulim: The test ''resets date when input is cleared'' introduced by this PR hasn't ever passed. At least if I git checkout 1e5df180bb1323bd7bf73c7f440760921b3fe708, update ember to 1.13.13 and run tests against it fails.