Add today button to flatpickr

See original GitHub issue

Hey, I am want to add a ‘today’ button on the ember-flatpickr.

I found this plugin but I can’t make it work. Maybe it’s out of scope, cause already the flatpickr doesn’t support a today button, but I believe many people would like this feature.

Another approach would be to add the button by using ember-elsewhere although I couldn’t target the .flatpickr-calendar to add the button.

Is there another option I could use for this?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
rwwagner90commented, Jun 5, 2019

@teakap

Sure. I cloned the repo, but I wasn’t able to understand how the code works. I was expecting to find something like components ex. flatpickr-months. Am I cloning the correct repo? When I run it it shows the page of the docs. Probably I’m missing something huge, but can’t figure it out 😃

The docs have a demo of the component functionality. You can play with the component there.

Nevermind, I got it. You extend the flatpickr. So actually… if we want to add properly a today btn, I will need to make a PR to the flatpickr.

ember-flatpickr wraps flatpickr. We are able to add extra functionality here. It could be an enhancement to ember-flatpickr, rather than flatpickr itself.

So I guess the flatpickrRef doesn’t behave as flatpickr (like a constructor) right? Do you see any workarounds ?

flatpickrRef is set to the flatpickr reference, after it is initialized. The reason it is not defined here, is didInsertElement will run before the flatpickr is created.

ember-flatpickr passes everything down to flatpickr, so you should be able to create an instance of the plugin in init and pass it into ember-flatpickr.

Something like this:

// my-datepicker.js

init() {
  this._super(...arguments);
  
  this.plugins = [
                ShortcutButtonsPlugin({
                    button: [{
                        label: "Beginning Of Time"
                    }],
                    label: "or",
                    onClick: (index, fp) => {
                        fp.setDate("1970/01/01 00:00");
                    }
                })
            ];
}
{{ember-flatpickr
        onChange=(action 'updateDate')
        getFlatpickrRef=(action (mut flatpickrRef))
        flatpickrRef=flatpickrRef
        altInput=true
        date=date
        id="calendar"
        altFormat="D, d M, Y"
        plugins=this.plugins
    }}

Does this make sense?

0reactions
teakapcommented, Jun 6, 2019

Yiap, it totally makes sense!

ember-flatpickr wraps flatpickr. We are able to add extra functionality here. It could be an enhancement to ember-flatpickr, rather than flatpickr itself.

I will work on it to see how this can be implemented then! Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Optional "Today" button in the calendar view #576 - GitHub
I made a small plugin, I mean, it's pretty easy to add some DOM to the calendar when onReady() but the UX of...
Read more >
Options - Flatpickr
Config Option Type Default altFormat String "F j, Y" altInput Boolean false altInputClass String ""
Read more >
shortcut-buttons-flatpickr - npm
Shortcut buttons is a plugin for flatpickr that provides users an alternative way to interact with the datetime picker.
Read more >
Add Open/Close/Clear Buttons - Integrating Flatpickr.js
Add Open/Close/Toggle Buttons to Calendar ... Note that with this page, we're not initializing the calendar by searching for the class, but rather...
Read more >
Set current date as "today" in the result using Flatpickr
I am using Flatpickr for my date picker. however, when i select today's date, i want the result to be displayed as "Today"....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found