Vue Range Presets

The selected range can be adjusted by the user or you can programmatically set the start and end.

This is especially useful and effective when using the range for filtering and you'd like to offer predefined ranges like Yesterday, Today, Last week and so on. Setting the values can be done from something as simple as a button click.

Get started with this example

Demo

Setting today
<script setup>
const now = new Date()
const myValue = ref(null)

function setToday() {
  myValue.value = [now, now]
}
</script>

<template>
  <MbscButton @click="setToday">Today</MbscButton>
  <MbscDatepicker v-model="myValue" :controls="['calendar']" select="range" />
</template>
Setting yesterday
<script setup>
const now = new Date()
const myValue = ref(null)

function setToday() {
  myValue.value = [now, now]
}
</script>

<template>
  <MbscButton @click="setToday">Today</MbscButton>
  <MbscDatepicker v-model="myValue" :controls="['calendar']" select="range" />
</template>
Setting this week
<script setup>
const now = new Date()
const firstday = new Date(now.setDate(now.getDate() - now.getDay()));
const lastday = new Date(now.setDate(now.getDate() - now.getDay() + 6));
const myValue = ref(null)

function setWeek() {
  myValue.value = [firstday, lastday]
}
</script>

<template>
  <MbscButton @click="setWeek">This week</MbscButton>
  <MbscDatepicker v-model="myValue" :controls="['calendar']" select="range" />
</template>
Setting last month
<script setup>
const now = new Date()
const firstday = new Date(now.getFullYear(), now.getMonth() - 1, 1)
const lastday = new Date(now.getFullYear(), now.getMonth(), 0)
const myValue = ref(null)

function setMonth() {
  myValue.value = [firstday, lastday]
}
</script>

<template>
  <MbscButton @click="setMonth">Last month</MbscButton>
  <MbscDatepicker v-model="myValue" :controls="['calendar']" select="range" />
</template>
Clear the selection with a simple click
<script setup>
const myValue = ref(null)

function clear() {
  myValue.value = null
}
</script>

<template>
  <MbscButton @click="clear">Clear</MbscButton>
  <MbscDatepicker v-model="myValue" :controls="['calendar']" select="range" />
</template>

Duplicate Session

You have signed in on a different machine. To keep everything in sync, you have been signed out of this session.

If you need to invite team members, manage seats and accounts you can do it from the licenses page.

Duplicate Session

We noticed you are logged in on a different machine and have closed your old session.

If you need to invite team members, manage seats and accounts you can do it from the licenses page.