I want to create a template for the append icon (multi icon).
When I click on the icon, it will focus on the input field.
How to prevent it?
[1]: https://codepen.io/tructubinh/pen/ExoyMrv?editors=101
Use :append-icon and #click:append. That should work.
<v-text-field
v-model="password"
:rules="[rules.required, rules.min]"
:type="show1 ? 'text' : 'password'"
name="input-10-1"
label="Normal with hint text"
hint="At least 8 characters"
counter
:append-icon="show1 ? 'mdi-eye-off' : 'mdi-eye'"
#click:append="show1 = !show1"
/>
EDIT
If you want to use a template you have to use .stop for the mouseup and click event.
<v-text-field
v-model="password"
:rules="[rules.required, rules.min]"
:type="show1 ? 'text' : 'password'"
name="input-10-1"
label="Normal with hint text"
hint="At least 8 characters"
counter
>
<template v-slot:append>
<v-icon #mouseup.stop #click.prevent.stop="show1 = !show1"> {{ show1 ? 'mdi-eye-off' : 'mdi-eye' }} </v-icon>
</template>
</v-text-field>
looks like append-outer is the right slot for this, you might need CSS tweaks to get this to match your designs
Use a ref to access the v-text-field's blur() method when clicking on the appended eye icon. This will remove the focus from the field.
Template:
<v-text-field
v-model="password"
...
ref="myTextField"
>
<template v-slot:append>
<v-icon #click="onClickAppendIcon">
{{ show1 ? 'mdi-eye-off' : 'mdi-eye' }}
</v-icon>
</template>
</v-text-field>
Script:
onClickAppendIcon() {
this.show1 = !this.show1
this.$refs.myTextField.blur()
}
Related
I am trying to do something with v-autocomplete where the default position for v-autocomplete is on the right side of the field, where I want the field to have icon on the left side before the selected content.
I have tried using prepend-icon slot but that isn't working as intended.
here is sample code
<v-autocomplete
ref="city"
v-model="city"
:loading="showCitiesLoading"
:disabled="showCitiesLoading"
dense
outlined
clearable
:rules="[requiredRule]"
color="black"
item-text="name"
item-value="name"
item-color="black"
:items="citiesList"
append-icon=""
#click="isOpen = !isOpen"
>
<template #prepend-inner>
<v-icon #click="isOpen = !isOpen">{{ isOpen ? mdiMenuDown : mdiMenuUp }}</v-icon>
</template>
</v-autocomplete>
and also in above section I have made isOpen to false on default inside Data property.
Thank You
Try to use the prepend-item slot. And remove your append-icon property too.
<v-autocomplete
ref="city"
v-model="city"
:loading="showCitiesLoading"
:disabled="showCitiesLoading"
dense
outlined
clearable
:rules="[requiredRule]"
color="black"
item-text="name"
item-value="name"
item-color="black"
:items="citiesList"
#click="isOpen = !isOpen"
>
<template #prepend-item>
<v-icon #click="isOpen = !isOpen">{{ isOpen ? mdiMenuDown : mdiMenuUp }}</v-icon>
</template>
</v-autocomplete>
I have a dynamic form that is constructed based off of json from the backend of input types, id, names, values, etc. One of my forms has two password fields that come from the backend. Is there a way to toggle visibility for multiple password fields on the same dynamic form? I'm having trouble figuring out how to do this to one at a time. Right now, the toggle icon switches both password fields on the screen.
<template>
<div class="pb-4" >
<template v-for="formField in formFields">
<v-row
:key="formField.key"
dense
align="center"
>
<v-col
md="3"
class="font-weight-bold text-right pr-10"
align-self="center"
>
{{formField.name}}
<span v-if="formField.required" class="small"> *</span>
</v-col>
<v-col
md="8"
align-self="center"
class="pl-3"
>
<v-text-field
v-if="formField.type === 'password'"
:id="formField.key"
:key="formField.key"
v-model="formField.value"
:append-icon="showPasswordIcon ? '$vuetify.icons.values.eye' : '$vuetify.icons.values.eyeSlash'"
:type="showPasswordIcon ? 'text' : 'password'"
:hint="getHintText(formField)"
:value="formField.name"
:required="formField.required"
:valid="(!formField.isValid) ? false : undefined"
dense
#input="inputHandler(formField)"
#blur="inputHandler(formField, false)"
#click:append="showPasswordIcon = !showPasswordIcon"
/>
<v-text-field
v-if="formField.type === 'text'"
:id="formField.key"
v-model="formField.value"
dense
:valid="(!formField.isValid) ? false : undefined"
#input="inputHandler(formField)"
#blur="inputHandler(formField, false)"
/>
<v-checkbox
v-if="formField.type === 'boolean'"
:id="formField.key"
v-model="formField.value"
class="mt-2"
/>
<v-text-field
v-if="formField.type === 'number'"
:id="formField.key"
v-model.number="formField.value"
dense
:valid="(!formField.isValid) ? false : undefined"
class="mb-0"
type="number"
#input="inputHandler(formField)"
#blur="inputHandler(formField, false)"
/>
</v-col>
</v-row>
</template>
</div>
</template>
Thank you so much for any tips on this!
Easiest solution might be to add an extra property to each element in the formFields, like visible, that tracks if a password should show its text. You can do that on API response and then insert it.
Then in your loop you can do
:type="formField.visible ? 'text' : 'password'"
This way, every formField is responsible for their own password visibility.
Next, you change
#click:append="showPasswordIcon = !showPasswordIcon"
to
#click:append="toggleShowPassword(formField.key)"
toggleShowPassword(key){
let formfield = this.formfields.find(x => x.key === key)
if(formfield){
formfield.visible = !formfield.visible
}
}
That should work!
I have a vuetify datatable, the original solution is dynamic allocation of search text field using v-for for each of the column and then multi filter is implemented. following is my solution:
<template v-for="(header, i) in columns" v-slot:[`header.${header.value}`]="{ }">
{{ header.text }}
<v-text-field :key="i"
v-model="multiSearch[header.value]"
class="pa"
type="text"
:placeholder="header.value"
prepend-inner-icon="mdi-magnify"
></v-text-field>
</template>
The problem is whenever an user clicks on the text field of a particular column, the sorting function also runs at the same time. I have a miniature solution on the following pen which has the same behaviour. I tried to put one div after template tag but still the same. Kindly have a look at it. Any help would be appreciated.
Code Pen
Wrap the text field with a DIV and attach an empty handler to prevent the bubbling of CLICK events:
<template v-for="(header, i) in columns" v-slot:[`header.${header.value}`]="{ }">
{{ header.text }}
<div #click.stop>
<v-text-field :key="i"
v-model="multiSearch[header.value]"
class="pa"
type="text"
:placeholder="header.value"
prepend-inner-icon="mdi-magnify"
></v-text-field>
</div>
</template>
I have a vue.js application with Vuetify. I have a couple of v-text-fields that look like this:
I would like to do 2 things:
Move the icons to the right.
Change the color of the icons.
There are suggestions on stackoverflow for how to do this but nothing worked in my case so I'm looking for some fresh ideas.
This is how the first v-text-field is implemented:
<v-text-field
slot="activator"
v-model="date"
label="Date"
prepend-inner-icon="$vuetify.icons.calendar"
:rules="[(v) => !!v || 'Date is required']"
required
readonly
outline
></v-text-field>
This is how the second v-text-field is implemented:
<v-text-field
slot="activator"
ref="text-field"
clearable
:label="label"
:value="content"
:prepend-inner-icon="showIcon ? '$vuetify.icons.clock' : ''"
readonly
outline
:rules="[v => required == null || !!v || label + ' is required',
v => !isInPast || pastValidationMessage,
v => !startAfterEnd || startAfterEndValidationMessage]"
:required="required"
#click:clear="onClear()"
></v-text-field>
It would be nice to also be able to change the color of the outline. That too I've found answers to but none that actually worked in my case.
Thanks.
You could use prepend slot instead of the prop:
<v-text-field label="Date">
<template #prepend>
<v-icon color="blue" right>
mdi-calendar
</v-icon>
</template>
</v-text-field>
LIVE DEMO
How to add two or more properties on the same slot on Datatable Vuetify 2.0
I use below code for only one property called active, but if I want to use it for few other properties means (like status, is_user and etc), how can I use that? any OR condition on v-slot
<template v-slot:item.active="{ item }">
<v-icon class="font--style"> {{ item.active ? 'done' : 'clear' }} </v-icon>
</template>
Thanks in advance!
Maybe this extended example can help you to figure it out.
Here is the link https://codepen.io/anon/pen/aeVjBK?editors=1010
<template v-slot:item.fat="{ item }">
<v-icon :color="item.fat > 10 ? 'red' : 'green'">{{ item.fat > 10 ? 'done' : 'clear' }}</v-icon>
<span>({{item.fat}}%)</span>
</template>
After the response from Vuetify Discord Chennal
We can do something like this to achieve by having a list of column names in the array,
let listOfColumns = ['isActive', 'isUser']
<template v-for="(column, index) in listOfColumns" #[`item.${column}`]="{ item }">
<v-icon class="font--style" :key="index"> {{ item[column] ? 'done' : 'clear' }} </v-icon>
</template>
Thanks !!!