S
S
Sergey750il2021-04-13 00:08:47
Vue.js
Sergey750il, 2021-04-13 00:08:47

How to disable all dates except a few in the datepicker?

I'm using this datepicker plugin but can't figure out how to disable all but a few dates?

<script>
import Datepicker from "vuejs-datepicker";
import { ru } from "vuejs-datepicker/dist/locale";
export default {
  data() {
    return {
      ru: ru,
      highlighted: {
        // dates: [
        //   // Highlight an array of dates
        //   new Date(2021, 3, 16),
        //   new Date(2021, 4, 17),
        //   new Date(2021, 4, 18),
        // ],
 
    
        includeDisabled: false, // Highlight disabled dates
      },
    };
  },
  components: {
    Datepicker,
  },
};
</script>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
0
0xD34F, 2021-04-13
@Sergey750il

data() {
  return {
    dates: [ массив допустимых дат, в числовом виде (количество миллисекунд) ],
    disabledFn: {
      customPredictor: date => !this.dates.includes(new Date(date).setHours(0, 0, 0, 0)),
    },
  };
},

<datepicker :disabledDates="disabledFn" />
https://codesandbox.io/s/for-httpsqnahabrcomq97203...

R
Rsa97, 2021-04-13
@Rsa97

Use customPredictor. Write a function that will return false for the dates you want to allow and true for all others.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question