uxsolutions / bootstrap-datepicker

A datepicker for twitter bootstrap (@twbs)
Apache License 2.0
12.68k stars 6.06k forks source link

Range picker as component #1033

Open stevelacey opened 10 years ago

stevelacey commented 10 years ago

Is there any way to use the range picker as a component, i.e. not dropping down from an input?

I am building an interface which allows uses to switch between "multiple date" and "date range" modes, so consistency between the two would be good, and I want to use component for both.

stevelacey commented 10 years ago

I determined that there is no support for this, however it is pretty easy to set up manually.

Simply instantiate 2 datepickers, and then replicate the adding of the range classes in the beforeShowCallback, and process the data yourself.

options
  beforeShowDay: (date) =>
    classes = []

    if @dates().length == 2
      classes.push 'range' if date >= @dates()[0] and date <= @dates()[1]

    classes: classes.join ' '

NB: my example is pretty much lifted out of my implementation and won't /just work/, @dates() returns an array of regular JS Date objects that I pull out of the form I populate manually in the changeDate callback.