I am trying to understand how the template works for the day calendar in Vuetify. When I am not using the template the data shows up in the proper time, when I add in the template it disappears. What am i missing?
Here is the code.
<v-calendar
color="primary"
type="day"
:events="events"
first-interval="6"
interval-count="14"
>
<template v-slot:day="{ start, end, name, checkedIn }">
<v-row class="fill-height">
<v-sheet color="orange lighten-2">
Hello, world! I'm a simple v-sheet {{start}} {{end}} {{name}} {{checkedIn}}
</v-sheet>
</v-row>
</template>
</v-calendar>
Do you mean something like this ?
Vue.config.productionTip = false;
Vue.config.devtools = false;
new Vue({
el: '#app',
vuetify: new Vuetify(),
template: '#main',
data:
{
focus: '2020-04-05',
events:
[
{
name: 'test',
start: '2020-04-05 10:00:00',
end: '2020-04-05 11:30:00',
color: 'cyan',
},
{
name: 'test',
start: '2020-04-05 07:00:00',
end: '2020-04-05 07:25:00',
color: 'green',
},
{
name: 'test',
start: '2020-04-05 08:00:00',
end: '2020-04-05 08:15:00',
color: 'red',
},
]
},
})
<link href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/#mdi/font#4.x/css/materialdesignicons.min.css" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/vuetify#2.x/dist/vuetify.min.css" rel="stylesheet">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no, minimal-ui">
<script src="https://cdn.jsdelivr.net/npm/vue#2.x/dist/vue.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vuetify#2.x/dist/vuetify.js"></script>
<div id="app"></div>
<template id="main">
<v-app>
<v-calendar
v-model="focus"
color="primary"
:events="events"
type="day"
>
<template v-slot:event="{event}">
<div :style="{'background-color':event.color,color:'white'}" class="fill-height pl-2">{{ event.name }}</div>
</template>
</v-calendar>
</v-app>
</template>
Related
I am using Vue and Vuetify and I want to show a green tick in front of the selected radio button. Right now it is at the bottom like this-
But I want it in the front of the selected radio button.
Here is my code-
<v-radio-group v-model="gstnRadio">
<v-radio
v-for="n in gstnArr"
color="#A01C40"
:key="n"
:label="`${n}`"
:value="n"
></v-radio>
</v-radio-group>
<v-tooltip v-if="gstnSelected">
<template v-slot:activator="{ on }">
<v-icon class="showHidePassword" color="green" v-on="on">check_circle</v-icon>
</template>
</v-tooltip>
EXPECTATION
GSTN abc
GSTN 123 (green tick here when this radio button is selected)
GSTN xyz
Totally blank as to what to do in order to achieve this.
Using slots, you can do this. Here is the working example-
<!DOCTYPE html>
<html>
<head>
<link href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/#mdi/font#4.x/css/materialdesignicons.min.css" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/vuetify#2.x/dist/vuetify.min.css" rel="stylesheet">
</head>
<body>
<div id="app">
<v-app>
<v-radio-group v-model="gstnRadio">
<v-radio
v-for="n in gstnArr"
color="#A01C40"
:key="n"
:label="`${n}`"
:value="n"
>
<template v-slot:label>
{{ n }}
<v-icon v-if="n == gstnRadio" class="ms-2 showHidePassword" color="green" v-on="on">mdi mdi-check-circle</v-icon>
</template>
</v-radio>
</v-radio-group>
</v-app>
</div>
<script src="https://cdn.jsdelivr.net/npm/vue#2.x/dist/vue.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vuetify#2.x/dist/vuetify.js"></script>
<script>
new Vue({
el: '#app',
vuetify: new Vuetify(),
data () {
return {
gstnRadio: null,
gstnArr: [
"GSTN abc", "GSTN 123", "GSTN xyz"
]
}
},
})
</script>
</body>
</html>
I am using v-date-picker component
when I select a month and then
change type props from month to date
using a select option that I provided in the from .
I see an error
and this is vuetify date-picker component
<v-date-picker
full-width
:locale="currentLocale"
v-model="form.date"
:range="range"
:type="calType"
:first-day-of-week="1"
>
</v-date-picker>
so, how can I fix this error ?
I don't know why you are getting this error but this is how you can change the type of date picker
new Vue({
el: '#app',
vuetify: new Vuetify(),
data () {
return {
currentLocale: 'en',
selectOptions: [{key: 'date', value: 'Date'}, { key: 'month', value: 'Month'}],
calType: 'date',
range: '',
picker: '',
}
},
methods: {
selectType($event) {
this.calType = $event;
},
},
})
<link href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/#mdi/font#4.x/css/materialdesignicons.min.css" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/vuetify#2.x/dist/vuetify.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/vue#2.x/dist/vue.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vuetify#2.x/dist/vuetify.js"></script>
<div id="app">
<div id="app">
<v-app id="inspire">
<v-row justify="center">
<v-col>
<v-select
v-model="calType"
label="select date type"
item-text="value"
item-value="key"
:items="selectOptions"
dense
single-line
:first-day-of-week="1"
:range="range"
v-on:change="selectType($event)"
>
</v-select>
</v-col>
<v-col>
<v-date-picker v-model="picker" :type="calType"></v-date-picker>
</v-col>
</v-row>
</v-app>
</div>
</div>
I don't know why you are getting this error but this is how you can change the type of date picker
new Vue({
el: '#app',
vuetify: new Vuetify(),
data () {
return {
currentLocale: 'en',
selectOptions: [{key: 'date', value: 'Date'}, { key: 'month', value: 'Month'}],
calType: 'date',
range: '',
}
},
methods: {
selectType($event) {
this.calType = $event;
},
},
})
<link href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/#mdi/font#4.x/css/materialdesignicons.min.css" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/vuetify#2.x/dist/vuetify.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/vue#2.x/dist/vue.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vuetify#2.x/dist/vuetify.js"></script>
<div id="app">
<div id="app">
<v-app id="inspire">
<v-row justify="center">
<v-col>
<v-select
v-model="calType"
label="select date type"
item-text="value"
item-value="key"
:items="selectOptions"
dense
single-line
v-on:change="selectType($event)"
>
</v-select>
</v-col>
<v-col>
<v-date-picker v-model="picker" :type="calType"></v-date-picker>
</v-col>
</v-row>
</v-app>
</div>
</div>
I want to close collapse when resize the window.
var app = new Vue({
el: '#app',
created() {
window.addEventListener('resize', this.hideCollapse)
},
destroyed() {
window.removeEventListener('resize', this.hideCollapse)
},
methods: {
hideCollapse() {
console.log('hide collapse')
// what should I call to make the collapse hide
}
}
})
<link type="text/css" rel="stylesheet" href="https://unpkg.com/bootstrap#4.5.3/dist/css/bootstrap.min.css" />
<link type="text/css" rel="stylesheet" href="https://unpkg.com/bootstrap-vue#2.21.2/dist/bootstrap-vue.css" />
<script src="https://unpkg.com/vue#2.6.12/dist/vue.min.js"></script>
<script src="https://unpkg.com/bootstrap-vue#2.21.2/dist/bootstrap-vue.min.js"></script>
<div id="app">
<b-button v-b-toggle.collapse-1 variant="primary">Toggle Collapse</b-button>
<b-collapse id="collapse-1" class="mt-2">
<b-card>
<p class="card-text">Collapse contents Here</p>
<b-button v-b-toggle.collapse-1-inner size="sm">Toggle Inner Collapse</b-button>
<b-collapse id="collapse-1-inner" class="mt-2">
<b-card>Hello!</b-card>
</b-collapse>
</b-card>
</b-collapse>
</div>
Add a data property called open and bind it to v-model directive of b-collapse component then update inside the resize event callback :
var app = new Vue({
el: '#app',
data() {
return {
open: false
}
},
created() {
window.addEventListener('resize', this.hideCollapse)
},
destroyed() {
window.removeEventListener('resize', this.hideCollapse)
},
methods: {
hideCollapse() {
console.log('hise collapse')
this.open=true
}
}
})
<link type="text/css" rel="stylesheet" href="https://unpkg.com/bootstrap#4.5.3/dist/css/bootstrap.min.css" />
<link type="text/css" rel="stylesheet" href="https://unpkg.com/bootstrap-vue#2.21.2/dist/bootstrap-vue.css" />
<script src="https://unpkg.com/vue#2.6.12/dist/vue.min.js"></script>
<script src="https://unpkg.com/bootstrap-vue#2.21.2/dist/bootstrap-vue.min.js"></script>
<!-- App -->
<div id="app">
<b-button v-b-toggle.collapse-1 variant="primary">Toggle Collapse</b-button>
<b-collapse v-model="open" id="collapse-1" class="mt-2">
<b-card>
<p class="card-text">Collapse contents Here</p>
<b-button v-b-toggle.collapse-1-inner size="sm">Toggle Inner Collapse</b-button>
<b-collapse id="collapse-1-inner" class="mt-2">
<b-card>Hello!</b-card>
</b-collapse>
</b-card>
</b-collapse>
</div>
Vuetify provides a select field component that is used for collecting user provided information from a list of options.
Here for the documentation
The component works with check boxes, so each time you check an item, it is added at the end of the list.
Now what I'd like to do is adding the same item on the list multiple times, so each time you click the item it is added at the end of the list. Is this achievable with Vuetify?
So the image is a bit misleading. If you would like to get tag input with autosuggestions, then I would rather keep it separate.
It would be possible to enhance the example below with v-text-field, but feels kinda hacky to me.
Please let me know how does this solution suite you :)
new Vue({
el: '#app',
vuetify: new Vuetify({ icons: { iconfont: 'md' } }),
data: () => ({
options: [
{ id: 1, name: 'foo' },
{ id: 2, name: 'bar' },
{ id: 3, name: 'fizz' }],
value: [
{ id: 1, name: 'foo' },
{ id: 1, name: 'foo' }
],
}),
})
<script src="https://cdn.jsdelivr.net/npm/babel-polyfill/dist/polyfill.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vue#2.x/dist/vue.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vuetify#2.x/dist/vuetify.js"></script>
<link href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Material+Icons" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/vuetify#2.x/dist/vuetify.min.css" rel="stylesheet">
<div id="app">
<v-app id="inspire">
<v-container fluid>
<v-row>
<v-col cols="12" sm="12">
<v-chip class='mr-2' v-for='({id, name}, i) in value'>
{{ id }}: {{ name }}
<v-icon class='ml-2' small #click='value.splice(i, 1)'>close</v-icon>
</v-chip>
<v-menu>
<template v-slot:activator='{ on }'>
<v-btn icon v-on='on' class='green'>
<v-icon>add</v-icon>
</v-btn>
</template>
<v-list>
<v-list-item v-for='o in options' #click='value.push(o)'>
<v-list-item-title>{{ o.name }}</v-list-item-title>
</v-list-item>
</v-list>
</v-menu>
</v-col>
<v-col>
<pre>{{ value }}</pre>
</v-col>
</v-row>
</v-container>
</v-app>
</div>
If you have items with same name, you need to use it's distinct property (here it is "id") to tell the difference.
and use item-text & item-value as shown in the example.
new Vue({
el: '#app',
vuetify: new Vuetify(),
data: () => ({
items: [
{ id: 1, name: 'foo' },
{ id: 2, name: 'bar' },
{ id: 3, name: 'foo' },
{ id: 4, name: 'fizz' },
{ id: 5, name: 'bar' }],
value: null,
}),
})
<script src="https://cdn.jsdelivr.net/npm/babel-polyfill/dist/polyfill.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vue#2.x/dist/vue.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vuetify#2.x/dist/vuetify.js"></script>
<link href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/#mdi/font#4.x/css/materialdesignicons.min.css" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/vuetify#2.x/dist/vuetify.min.css" rel="stylesheet">
<div id="app">
<v-app id="inspire">
<v-container fluid>
<v-row align="center">
<v-col cols="12" sm="6">
<v-select v-model="value" :items="items" item-text="name" item-value="id" attach chips label="Chips" multiple></v-select>
</v-col>
<v-col>
<pre>{{ value }}</pre>
</v-col>
</v-row>
</v-container>
</v-app>
</div>
I have a v-switch that I'd like to be "on/true" so that the switch is to the right, but still have the v-model value to be "false", and then when the switch is "off/false" have the v-model value to be "true", essentially inverting the values.
I'm struggling to find this an option or how to do this. I'm using Vuetify 1.5.15:
<v-switch color="success" prepend-icon="notifications_off" v-model="url.muteNotifications" #click.capture.prevent.stop="togglePolling(url, urlNo)"></v-switch>
its not value - its input-value
new Vue({
el: '#app',
data(){
return {
t:false
}
},
methods: {
change(){
console.log("change");
this.t=!this.t;
}
},
vuetify: new Vuetify(),
})
<link href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/#mdi/font#3.x/css/materialdesignicons.min.css" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/vuetify#2.x/dist/vuetify.min.css" rel="stylesheet">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no, minimal-ui">
<script src="https://cdn.jsdelivr.net/npm/vue#2.x/dist/vue.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vuetify#2.x/dist/vuetify.js"></script>
<div id="app">
<v-app>
<v-content>
<v-switch :input-value="!t" #change="change">Hello world</v-switch>
</v-content>
</v-app>
</div>
but you can also define false as truish
new Vue({
el: '#app',
data(){
return {
t:false
}
},
vuetify: new Vuetify(),
})
<link href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/#mdi/font#3.x/css/materialdesignicons.min.css" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/vuetify#2.x/dist/vuetify.min.css" rel="stylesheet">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no, minimal-ui">
<script src="https://cdn.jsdelivr.net/npm/vue#2.x/dist/vue.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vuetify#2.x/dist/vuetify.js"></script>
<div id="app">
<v-app>
<v-content>
<v-switch v-model="t" :false-value="true" :true-value="false">Hello world</v-switch>
</v-content>
</v-app>
</div>
but this breaks colors - imo a bug
Decompose model on value and change and reverse the algorithm, like this:
<v-switch :value="!mute" #change="(v) => mute = !v" :label="`Switch mute: ${mute.toString()}`"></v-switch>
v-model & reversed
<div id="app">
<v-app id="inspire">
<v-container fluid>
<v-switch v-model="mute" :label="`Switch mute: ${mute.toString()}`"></v-switch>
<v-switch :value="!mute" #change="(v) => mute = !v" :label="`Switch mute reversed: ${mute.toString()}`"></v-switch>
</v-container>
</v-app>
</div>
<script>
new Vue({
el: '#app',
data () {
return {
mute: true
}
}
})
</script>
For an Array
<div id="app">
<v-app id="inspire">
<v-container fluid>
<div v-for="(sound, index) in sounds" :key="index">
<v-switch v-model="sound.mute" :label="`Switch mute of ${sound.name}: ${sound.mute.toString()}`"></v-switch>
<v-switch :value="!sound.mute" #change="(v) => sound.mute = !v" :label="`Switch mute of ${sound.name} reversed: ${sound.mute.toString()}`"></v-switch>
</div>
</v-container>
</v-app>
</div>
new Vue({
el: '#app',
data () {
return {
sounds: [{name:'first', mute: true}, {name:'second', mute: true}]
}
}
})
Live example: https://codepen.io/andriykuba/pen/abomQYe
Vuetify default value is true/false
<v-switch
v-model="sales.final_info.reverse_charge"
></v-switch>
Vuetify custom switch value set by false-value and true-value attribute
<v-switch
false-value="NO"
true-value="YES"
v-model="sales.final_info.reverse_charge">
</v-switch>