Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Date / moment objects #262

Open
betocantu93 opened this issue Sep 17, 2019 · 0 comments
Open

Date / moment objects #262

betocantu93 opened this issue Sep 17, 2019 · 0 comments

Comments

@betocantu93
Copy link

betocantu93 commented Sep 17, 2019

Related issues: #6 #10

I think ember-pikaday already handles display for us, we shouldn't be managing setting the underlaying input value.

this function tries to reconcile this.value with the actual html5 input, but this is already handled by pikaday.

My proposal would be to pass down date objects, and let pikaday handle the formatting

 <PaperPikaday @value={{this.myDateOrMomentValue}} @onChange={{action (mut this.myDateOrMomentValue}} />

this.myDateOrMomentValue would always be a date/moment object, pikaday automagically handle the display formatting for us, and since the this.value is actually set via data down, the ember-paper validations should work out of the box.

ember-pikaday pikaday mixin already uses the didUpdateAttrs hook to update pikaday with newly passed down value, so we shouldn't be worried about having the underlaying input in sync with this.value, it would be handled by pikaday via this

Having date objects is compilant with ember-data date transform which should solve the ISO serializing automatically for us, I actually extended the transform to support moment, because we are using it

This simple override would let pikaday receive moment objects

setPikadayDate() {
    const format = "YYYY/MM/DD";
    const value = this.get('value');
    if (!value) {
      this.get('pikaday').setDate(value, true);
    } else {
      let date = this.get('useUTC') ? moment(moment.utc(value).format(format), format).toDate() : value;

      if (moment.isMoment(date)) {
        date = date.toDate();
      }
      this.get('pikaday').setDate(date, true);
    }

  },
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant