stimulus-flatpickr icon indicating copy to clipboard operation
stimulus-flatpickr copied to clipboard

Plugins support?

Open khalilgharbaoui opened this issue 7 years ago • 1 comments

How can we add support for these plugins?

https://flatpickr.js.org/plugins/#rangeplugin-beta

https://github.com/flatpickr/flatpickr/tree/master/src/plugins

I kind of solved it by importing for example the rangePlugin from flatpicker plugins folder:

 import rangePlugin from 'flatpickr/dist/plugins/rangePlugin.js'

And i used it in the config:

connect(){
  this.config = {
      mode: 'range', 
      plugins: [new rangePlugin({ input: "#secondRangeInput"})]
    }
  super.connect()
}

and then in the view i did:

<%= text_field_tag :starts_at, nil,
      placeholder: 'select',
      data: {
       // ...
        controller: 'flatpickr',
        flatpickr_mode: 'range',
       // ...
      } %>
<%= text_field_tag :ends_at, nil, id: 'secondRangeInput' %>

It works but i feel this should be part of the stimulus-flatpicker's api without having to import stuff.

Thanks,

Khalil Gharbaoui

khalilgharbaoui avatar Nov 01 '18 04:11 khalilgharbaoui

Hello

I haven’t documented this yet but what you ended up doing is how I would do it. I am afraid that importing all plugins into the stimulus-flatpickr wrapper would increase the size with lots of unnecessary stuff. Tree shaking would probably work for this but not everyone is using bundlers with tree shaking

adrienpoly avatar Nov 01 '18 07:11 adrienpoly