Flight Booking
For a great booking experience a good date picker is essential. The best implementations are contextual and take the intent (what people want to do) and context (where and how are they doing it) into account. Learn how to use and customize the range picker and see how you can add your flavor that matches with the overall experience of your application.
Demo
When building flight booking systems you want to make sure that you set up min & max boundaries for the selectable days. This way you ensure that people can't select dates from the past.
The range picker can be set up on one or two inputs. If you are building a fully custom experience, you can embed it into your own modal.
<script setup>
const now = new Date()
const min = now
const max = new Date(now.getFullYear(), now.getMonth() + 6, now.getDate())
</script>
<template>
<MbscDatepicker
select="range"
:controls="['calendar']"
:min="min"
:max="max"
/>
</template>
Instead of a single input you can have two, one for Outbound and another for Return.
<script setup>
const now = new Date()
const min = now
const max = new Date(now.getFullYear(), now.getMonth() + 6, now.getDate())
const startInput = ref(null)
const endInput = ref(null)
</script>
<template>
<MbscDatepicker
select="range"
:controls="['calendar']"
:startInput="startInput"
:endInput="endInput"
:min="min"
:max="max"
/>
<MbscInput ref="startInput" label="Outbound" placeholder="Please Select..." />
<MbscInput ref="endInput" label="Return " placeholder="Please Select..." />
</template>
Besides setting min & max boundaries, days without flights should be disabled. These could be single occurrence or recurring dates, like specific weekdays. Setting inRangeInvalid: true allows ranges to contain invalids, it only makes sure that the start and end dates are on valid days. If inRangeInvalid is false, no invalid dates are allowed inside a selection (useful for hotel booking).
<script setup>
const now = new Date()
const myInvalid = [
{
recurring: {
repeat: 'weekly',
weekDays: 'TU,TH'
}
},
new Date(now.getFullYear(), now.getMonth(), 25)
]
const startInput = ref(null)
const endInput = ref(null)
</script>
<template>
<MbscDatepicker
select="range"
:controls="['calendar']"
:startInput="startInput"
:endInput="endInput"
:invalid="myInvalid"
:inRangeInvalid="true"
/>
<MbscInput ref="startInput" label="Outbound" placeholder="Please Select..." />
<MbscInput ref="endInput" label="Return " placeholder="Please Select..." />
</template>
You will probably need to give people the option to select a single date for one way trips. This can be easily accomplished by dynamically setting the select option to 'date'. Toggling with a radio button between 'date'/'range' will switch between single date selection and range selection.
<script setup>
const bookingType = ref('round')
</script>
<template>
<MbscRadioGroup v-model="bookingType">
<MbscRadio value="round" label="Round trip" />
<MbscRadio value="oneway" label="One way" />
</MbscRadioGroup>
<MbscDatepicker
:select="bookingType == 'oneway' ? 'date' : 'range'"
:controls="['calendar']"
/>
</template>
If you don't want to add another control (like a radio button or segmented) to your UI, you can solve the "one way question" with a custom button on the dialog and a little custom logic. The idea is to track if at least one value is selected and dynamically enable the button.
<script setup>
const calendarRef = ref(null)
const booking = ref(null)
const myButtons = ref([
'cancel',
{
disabled: true,
text: 'One way only'
},
'set'
])
function changeTripType() {
const startDate = calendarRef.value.instance.getTempVal()[0]
flightButtons.value = [
'cancel',
{
disabled: startDate != undefined,
handler: () => {
booking.value = [startDate, null]
calendarRef.value.instance.close()
},
text: 'One way only'
},
'set'
]
}
</script>
<template>
<MbscDatepicker
ref="calendarRef"
v-model="booking"
select="range"
:controls="['calendar']"
:buttons="myButtons"
@temp-change="changeTripType"
/>
</template>
<script setup>
import {
MbscDatepicker,
MbscInput,
MbscPage,
MbscRadio,
MbscRadioGroup,
setOptions
} from '@mobiscroll/vue'
import { ref } from 'vue'
setOptions({
locale: ,
theme: ' ',
themeVariant: ' '
})
const now = new Date()
const booking = ref()
const min = now
const max = new Date(now.getFullYear(), now.getMonth() + 6, now.getDate())
const myInvalid = [
{
recurring: {
repeat: 'weekly',
weekDays: 'TU,TH'
}
},
new Date(now.getFullYear(), now.getMonth(), 25)
]
const calendarRef = ref(null)
const outboundInput = ref(null)
const returnInput = ref(null)
const outboundInv = ref(null)
const returnInv = ref(null)
const outboundBooking = ref(null)
const returnBooking = ref(null)
const trip = ref('round')
const flightButtons = ref([
'cancel',
{
disabled: true,
text: 'One way only'
},
'set'
])
function changeTripType() {
const startDate = calendarRef.value.instance.getTempVal()[0]
flightButtons.value = [
'cancel',
{
disabled: startDate != undefined,
handler: () => {
booking.value = [startDate, null]
calendarRef.value.instance.close()
},
text: 'One way only'
},
'set'
]
}
</script>
<template>
<MbscPage>
<div class="mbsc-grid mbsc-no-padding">
<div class="mbsc-row">
<div class="mbsc-col-12">
<MbscDatepicker
:controls="['calendar']"
select="range"
:min="min"
:max="max"
:pages="2"
:buttons="['set', 'cancel']"
label="Pick your flight"
inputStyle="outline"
labelStyle="stacked"
placeholder="Please select..."
/>
</div>
</div>
<div class="mbsc-row">
<div class="mbsc-col-6">
<MbscDatepicker
:controls="['calendar']"
select="range"
:min="min"
:max="max"
:pages="2"
:startInput="outboundInput"
:endInput="returnInput"
/>
<MbscInput
ref="outboundInput"
label="Outbound"
inputStyle="outline"
labelStyle="stacked"
placeholder="Please Select..."
/>
</div>
<div class="mbsc-col-6">
<MbscInput
ref="returnInput"
label="Return"
inputStyle="outline"
labelStyle="stacked"
placeholder="Please Select..."
/>
</div>
</div>
<div class="mbsc-row">
<div class="mbsc-col-6">
<MbscDatepicker
:controls="['calendar']"
select="range"
:min="min"
:max="max"
:pages="2"
:invalid="myInvalid"
:inRangeInvalid="true"
:startInput="outboundInv"
:endInput="returnInv"
/>
<MbscInput
ref="outboundInv"
label="Outbound"
inputStyle="outline"
labelStyle="stacked"
placeholder="Please Select..."
/>
</div>
<div class="mbsc-col-6">
<MbscInput
ref="returnInv"
label="Return"
inputStyle="outline"
labelStyle="stacked"
placeholder="Please Select..."
/>
</div>
</div>
<div class="mbsc-row">
<MbscRadioGroup
v-model="trip"
name="flight-booking-type"
theme="material"
themeVariant="light"
>
<MbscRadio value="round" label="Round trip" theme="material" themeVariant="light" />
<MbscRadio value="oneway" label="One way" theme="material" themeVariant="light" />
</MbscRadioGroup>
</div>
<div class="mbsc-row">
<div class="mbsc-col-6">
<MbscDatepicker
:controls="['calendar']"
:select="trip == 'oneway' ? 'date' : 'range'"
:min="min"
:max="max"
:pages="2"
:startInput="outboundBooking"
:endInput="returnBooking"
label="Outbound"
inputStyle="outline"
labelStyle="stacked"
placeholder="Please Select..."
/>
<MbscInput
ref="outboundBooking"
label="Outbound"
inputStyle="outline"
labelStyle="stacked"
placeholder="Please Select..."
:hidden="trip == 'oneway'"
:style="{ display: trip == 'oneway' ? 'none' : 'block' }"
/>
</div>
<div class="mbsc-col-6">
<MbscInput
ref="returnBooking"
label="Return"
inputStyle="outline"
labelStyle="stacked"
placeholder="Please Select..."
:disabled="trip == 'oneway'"
/>
</div>
</div>
<div class="mbsc-row">
<div class="mbsc-col-12">
<MbscDatepicker
ref="calendarRef"
v-model="booking"
:controls="['calendar']"
select="range"
:buttons="flightButtons"
:min="min"
:max="max"
:pages="2"
label="Pick your flight"
inputStyle="outline"
labelStyle="stacked"
placeholder="Please select..."
@temp-change="changeTripType"
/>
</div>
</div>
</div>
</MbscPage>
</template>
<script setup lang="ts">
import {
MbscDatepicker,
MbscInput,
MbscPage,
MbscRadio,
MbscRadioGroup,
setOptions
} from '@mobiscroll/vue'
import { ref } from 'vue'
setOptions({
locale: ,
theme: ' ',
themeVariant: ' '
})
const now = new Date()
const booking = ref()
const min = now
const max = new Date(now.getFullYear(), now.getMonth() + 6, now.getDate())
const myInvalid = [
{
recurring: {
repeat: 'weekly',
weekDays: 'TU,TH'
}
},
new Date(now.getFullYear(), now.getMonth(), 25)
]
const calendarRef = ref<any>(null)
const outboundInput = ref<any>(null)
const returnInput = ref<any>(null)
const outboundInv = ref<any>(null)
const returnInv = ref<any>(null)
const outboundBooking = ref<any>(null)
const returnBooking = ref<any>(null)
const trip = ref<string>('round')
const flightButtons = ref<any>([
'cancel',
{
disabled: true,
text: 'One way only'
},
'set'
])
function changeTripType() {
const startDate = calendarRef.value.instance.getTempVal()[0]
flightButtons.value = [
'cancel',
{
disabled: startDate != undefined,
handler: () => {
booking.value = [startDate, null]
calendarRef.value.instance.close()
},
text: 'One way only'
},
'set'
]
}
</script>
<template>
<MbscPage>
<div class="mbsc-grid mbsc-no-padding">
<div class="mbsc-row">
<div class="mbsc-col-12">
<MbscDatepicker
:controls="['calendar']"
select="range"
:min="min"
:max="max"
:pages="2"
:buttons="['set', 'cancel']"
label="Pick your flight"
inputStyle="outline"
labelStyle="stacked"
placeholder="Please select..."
/>
</div>
</div>
<div class="mbsc-row">
<div class="mbsc-col-6">
<MbscDatepicker
:controls="['calendar']"
select="range"
:min="min"
:max="max"
:pages="2"
:startInput="outboundInput"
:endInput="returnInput"
/>
<MbscInput
ref="outboundInput"
label="Outbound"
inputStyle="outline"
labelStyle="stacked"
placeholder="Please Select..."
/>
</div>
<div class="mbsc-col-6">
<MbscInput
ref="returnInput"
label="Return"
inputStyle="outline"
labelStyle="stacked"
placeholder="Please Select..."
/>
</div>
</div>
<div class="mbsc-row">
<div class="mbsc-col-6">
<MbscDatepicker
:controls="['calendar']"
select="range"
:min="min"
:max="max"
:pages="2"
:invalid="myInvalid"
:inRangeInvalid="true"
:startInput="outboundInv"
:endInput="returnInv"
/>
<MbscInput
ref="outboundInv"
label="Outbound"
inputStyle="outline"
labelStyle="stacked"
placeholder="Please Select..."
/>
</div>
<div class="mbsc-col-6">
<MbscInput
ref="returnInv"
label="Return"
inputStyle="outline"
labelStyle="stacked"
placeholder="Please Select..."
/>
</div>
</div>
<div class="mbsc-row">
<MbscRadioGroup
v-model="trip"
name="flight-booking-type"
theme="material"
themeVariant="light"
>
<MbscRadio value="round" label="Round trip" theme="material" themeVariant="light" />
<MbscRadio value="oneway" label="One way" theme="material" themeVariant="light" />
</MbscRadioGroup>
</div>
<div class="mbsc-row">
<div class="mbsc-col-6">
<MbscDatepicker
:controls="['calendar']"
:select="trip == 'oneway' ? 'date' : 'range'"
:min="min"
:max="max"
:pages="2"
:startInput="outboundBooking"
:endInput="returnBooking"
label="Outbound"
inputStyle="outline"
labelStyle="stacked"
placeholder="Please Select..."
/>
<MbscInput
ref="outboundBooking"
label="Outbound"
inputStyle="outline"
labelStyle="stacked"
placeholder="Please Select..."
:hidden="trip == 'oneway'"
:style="{ display: trip == 'oneway' ? 'none' : 'block' }"
/>
</div>
<div class="mbsc-col-6">
<MbscInput
ref="returnBooking"
label="Return"
inputStyle="outline"
labelStyle="stacked"
placeholder="Please Select..."
:disabled="trip == 'oneway'"
/>
</div>
</div>
<div class="mbsc-row">
<div class="mbsc-col-12">
<MbscDatepicker
ref="calendarRef"
v-model="booking"
:controls="['calendar']"
select="range"
:buttons="flightButtons"
:min="min"
:max="max"
:pages="2"
label="Pick your flight"
inputStyle="outline"
labelStyle="stacked"
placeholder="Please select..."
@temp-change="changeTripType"
/>
</div>
</div>
</div>
</MbscPage>
</template>