Date Range in Vue Calendar
03 Sep 20263 minutes to read
Calendar provides an option to select a date value within a specified range by defining the min and max properties. The min date should always be less than the max date. If the values of the min or max properties are changed programmatically, then update the value property to be set within the specified range. Otherwise, if the value is out of the specified date range and less than the min date, the value property will be updated with the min date. If the value is higher than the max date, the value property will be updated with the max date.
The following example allows you to select a date within the range of 7th to 27th days in a month.
<template>
<div id="app">
<div class='wrap'>
<ejs-calendar id='calendar' :value='dateVal' :min='minVal' :max='maxVal'
placeholder='Select a Date'></ejs-calendar>
</div>
</div>
</template>
<script setup>
import { CalendarComponent as EjsCalendar } from "@syncfusion/ej2-vue-calendars";
var today = new Date();
var currentYear = today.getFullYear();
var currentMonth = today.getMonth();
const dateVal = new Date(new Date().setDate(14))
const minVal = new Date(currentYear, currentMonth, 7)
const maxVal = new Date(currentYear, currentMonth, 27)
</script>
<style>
@import "../node_modules/@syncfusion/ej2-base/styles/material.css";
@import "../node_modules/@syncfusion/ej2-buttons/styles/material.css";
@import "../node_modules/@syncfusion/ej2-vue-calendars/styles/material.css";
.wrap {
margin: 35px auto;
width: 240px;
}
</style><template>
<div id="app">
<div class='wrap'>
<ejs-calendar id='calendar' :value='dateVal' :min='minVal' :max='maxVal'
placeholder='Select a Date'></ejs-calendar>
</div>
</div>
</template>
<script>
import { CalendarComponent } from "@syncfusion/ej2-vue-calendars";
export default {
name: "App",
components: {
"ejs-calendar": CalendarComponent
},
data() {
var today = new Date();
var currentYear = today.getFullYear();
var currentMonth = today.getMonth();
return {
dateVal: new Date(new Date().setDate(14)),
minVal: new Date(currentYear, currentMonth, 7),
maxVal: new Date(currentYear, currentMonth, 27),
}
}
}
</script>
<style>
@import "../node_modules/@syncfusion/ej2-base/styles/material.css";
@import "../node_modules/@syncfusion/ej2-buttons/styles/material.css";
@import "../node_modules/@syncfusion/ej2-vue-calendars/styles/material.css";
.wrap {
margin: 35px auto;
width: 240px;
}
</style>