3

How can I disable future dates while using date range?

<date-picker
 v-model="params.range"
 type="date"
 value-type="format"
 format="YYYY-MM-DD"
 range
 placeholder="Filter by date range"
/>

1 Answer 1

4

You can use the disabled-date prop to provide a function telling if a date should be disabled or not.

From the vue2-datepicker documentation demo (source code)

<template>
  <div>
    <p>Not before than today and not after than a week</p>
    <date-picker
      v-model="value1"
      :default-value="new Date()"
      :disabled-date="disabledAfterToday"
    ></date-picker>
  </div>
</template>

<script>
export default {
  data() {
    return {
      value1: new Date(),
    };
  },
  methods: {
    disabledAfterToday(date) {
      const today = new Date();
      today.setHours(0, 0, 0, 0);
      return date > today
    },
  },
};
</script>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.