Giter VIP home page Giter VIP logo

Comments (7)

icolquemamani avatar icolquemamani commented on July 24, 2024

I have the same problem. Is there any solution?

from datetime-picker.

qweluke avatar qweluke commented on July 24, 2024

@matepaiva @icolquemamani @fooloomanzoo
did you found any solutions? I am using Stencil.js and also don't know how to get current date

from datetime-picker.

matepaiva avatar matepaiva commented on July 24, 2024

Nope! I just used another package, unfortunately.

from datetime-picker.

icolquemamani avatar icolquemamani commented on July 24, 2024

@qweluke @matepaiva
I have a partial solution, use the component in a class of polymer 3 without a lit-element, reuse the same in the class with lit-element. Manage to capture the date through personalized events.

<calendar-element auto-confirm date="{{date}}" min="{{min}}" first-day-of-week="0"></calendar- 
  element>
static get properties() {
        return {
          date: {
            type: String,
            notify: true,
            observer: '_dateChanged'
          },

          min: {
            type: String
          }
        };
      }
 _dateChanged(newValue, oldValue) {
          let event = new CustomEvent('change', {
            detail: { date: newValue }
          });
          this.dispatchEvent(event);
 }

I'm not sure if this can help you with the library that you are currently using "stencil.js".

from datetime-picker.

qweluke avatar qweluke commented on July 24, 2024

@matepaiva which package?

from datetime-picker.

daniel-sullivan avatar daniel-sullivan commented on July 24, 2024

Give this a try:

firstUpdated() {
        super.firstUpdated();

        let dtPicker = this.shadowRoot.querySelector('datetime-picker');
        dtPicker.shadowRoot.querySelector('button#confirm').addEventListener('click', () => {
            this.dispatchEvent(new CustomEvent('change', {
                detail: dtPicker
            }));
        })
    }

We've just needed to do something similar. In this case we're wrapping it in a lit-element component so we're passing the change event up to the parent.

If you are directly using the component from the same context you'd probably want something like:

firstUpdated() {
        super.firstUpdated();

        let dtPicker = this.shadowRoot.querySelector('datetime-picker');
        dtPicker.shadowRoot.querySelector('button#confirm').addEventListener('click', () => {
            this._handleDateChanged(dtPicker);
        })
    }

_handleDateChanged(dtPicker) {
    console.dir(dtPicker);
}

All of the parameters which you can get out are visible in the Developer Console in Chrome etc.

from datetime-picker.

acarapetis avatar acarapetis commented on July 24, 2024

After poking around in the source code of @fooloomanzoo/property-mixins/datetime-mixin and reading some Polymer documentation, I found that the property datetime has notify: true; so we can in fact listen for the datetime-changed custom event:

<datetime-picker
    datetime=${this.dateFrom}
    @datetime-changed=${e => this.dateFrom = e.target.datetime}
    ></datetime-picker>

It would be good to document all of the events available (or at least the more useful ones). As it stands it's quite hard to discover how to use this component outside of Polymer apps - it feels like a shame to throw away the versatility of being a portable webcomponent.

EDIT: This also isn't a perfect solution, since this event is fired not only on user input but also when the prop changes for any other reason, such as being programmatically updated, and on component initialization.

from datetime-picker.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.