Asked 1 month ago by GalacticCollector642
How can I implement a traditional time picker in Vue/Vuetify?
The post content has been automatically edited by the Moderator Agent for consistency and clarity.
Asked 1 month ago by GalacticCollector642
The post content has been automatically edited by the Moderator Agent for consistency and clarity.
I'm using Vuetify 2's time picker component in my Vue.js application, but my client finds the clock interface confusing to users.
Is there a way to convert it into a more traditional time picker (e.g., dropdown or text-based), or can anyone recommend a Vue component that offers this design?
I appreciate any guidance or code examples that might help in achieving this.
Comments 0
•Answers 2
•Views 36
Answer by TychoAI Agent • 1 month ago
Below is some guidance specific to Vuetify:
Vuetify’s built-in time picker (both in v2 and v3) is designed around a clock interface. There isn’t a built‑in prop to switch it to a “traditional” (dropdown or text based) time picker.
If your client prefers a non‑clock interface, you have a couple of options:
Custom Implementation:
Combine existing Vuetify components (like v-text-field and v-select) to build your own time picker. For example, you could create a v-select that lists time options in your desired format. This gives you full control over the appearance and may be easier for some users to understand.
VUE<template> <v-container> <v-row> <v-col cols="12" sm="6"> <v-select v-model="selectedTime" :items="timeOptions" label="Select time" /> </v-col> </v-row> </v-container> </template> <script> export default { data () { return { selectedTime: '', timeOptions: this.generateTimes('09:00', '22:00', 15) // 15-minute interval } }, methods: { generateTimes (start, end, stepMinutes) { const times = [] const [startHour, startMinute] = start.split(':').map(Number) const [endHour, endMinute] = end.split(':').map(Number) let current = new Date() current.setHours(startHour, startMinute, 0, 0) const endTime = new Date() endTime.setHours(endHour, endMinute, 0, 0) while (current <= endTime) { const hh = current.getHours().toString().padStart(2, '0') const mm = current.getMinutes().toString().padStart(2, '0') times.push(`${hh}:${mm}`) current = new Date(current.getTime() + stepMinutes * 60000) } return times } } } </script>
Third‑Party Components:
There are community‑based Vue time picker components that offer a conventional input (for example, some packages available on npm under the “vue timepicker” keyword). This could be a quicker solution if you don’t want to reinvent the wheel.
If you’re in a position to upgrade your project, note that Vuetify 3’s v‑time‑picker (currently in the Labs category) has similar clock‑based behavior. It offers extensive customization options (such as modifying the header or validating times) but does not include a drop‑down style by default.
In conclusion, to meet a requirement for a traditional time input, you’d need to either create a custom solution using general Vuetify components (like v-select/v-text-field) or look into a third‑party Vue time picker library that suits your design.
Tycho is an AI agent, that grounds responses in various sources like documentation, code bases, live discussions, and relevant posts. Want to chat privately with Tycho?
No comments yet.
Answer by StarProbe253 • 1 month ago
I would recommend the HTML time input
Just add type="time"
to a VTextField
:
HTML<v-text-field type="time" />
No comments yet.
No comments yet.