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

[Bug] Cannot use shortcuts with range #400

Closed
denilsonsa opened this issue Dec 16, 2019 · 2 comments
Closed

[Bug] Cannot use shortcuts with range #400

denilsonsa opened this issue Dec 16, 2019 · 2 comments

Comments

@denilsonsa
Copy link

Vue2-datepicker version: 3.2.2
Vue version: 2.6.10 (doesn't matter)
Browser: Chrome 78 (doesn't matter)

Steps to reproduce

  1. Enable the range prop.
    • Now, instead of one single date, this component works with an array of two elements.
  2. Generate a list of shortcuts, each one with onClick returning a list of two elements.
  3. Doesn't work. :(

Reproduction Link or Source Code

It should be reproducible with a code similar to this one (note: untested code snippet):

  <VueDatePicker
    type="datetime"
    range
    value-type="format"
    format="YYYY-MM-DD HH:mm:ss"
    v-model="foobar"
    :shortcuts="makeShortcuts"
  />
…
    makeShortcuts() {
      return [
        {
          text: 'Last hour',
          onClick: () => [new Date(Date.now() - 60 * 60 * 1000), new Date()],
        },
      ];
    },

It would be nice to add to the demo page one example using both shortcuts and range:

Expected behavior

If the shortcut returns an array of two dates, it should set the range to the returned array.

(Bonus!) If the shortcut returns only one date, then it could behave as if the user clicked on that date on the calendar; i.e. it would select either the start or the end of the range. This way, it would be possible to have a list of "key" dates and let the user click on them to set an arbitrary range between those dates. (When I say "date", please also consider the other types, such as datetime.)

Actual behavior

When the shortcut returns an array, the handleSelectShortcut function does nothing, because it checks if the value is a date before emitting it. In other words, this function does not support ranges.

However, if the shortcut returns a single date (even though the component is in range mode), that function blindly calls emitValue, which will emit the single date instead of the expected array, which will then break code outside of the component.

mengxiong10 added a commit that referenced this issue Dec 17, 2019
@mengxiong10
Copy link
Owner

mengxiong10 commented Dec 17, 2019

I'll fix it soon.

@mengxiong10
Copy link
Owner

v3.3.0 fixed it.

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

2 participants