Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vuetify input autocomplete bug

I tried to google it a couple of times but got no luck, basically, when the page loads since the password is on autosave the v-text-field doesn't understand it and renders the password content in front of the label, is there any workaround or fix for that?

Here is a ss:

enter image description here

The login component:

<template>
  <div>
    <v-card class="elevation-12">
      <v-toolbar color="primary" dark flat>
        <v-toolbar-title>Login</v-toolbar-title>
      </v-toolbar>
      <v-card-text>
        <v-form>
          <v-text-field
            label="E-mail"
            name="email"
            type="text"
            :rules="emailRules"
            :autofocus="'autofocus'"
          ></v-text-field>
          <v-text-field
            id="password"
            label="Senha"
            name="password"
            type="password"
          ></v-text-field>
        </v-form>
      </v-card-text>
      <v-card-actions>
        <v-spacer></v-spacer>
        <v-btn color="primary" block>Logar</v-btn>
      </v-card-actions>
    </v-card>
  </div>
</template>

<script>
  export default {
    name: "LoginForm",
    data: () => ({
      valid: true,
      email: '',
      password:'',
      emailRules: [
        v => !!v || 'Digite um e-mail',
        v => /.+@.+\..+/.test(v) || 'O e-mail precisa ser válido.',
      ]
    })
  }
</script>

<style lang="scss">
@import "LoginForm.scss";
</style>

The place where I use the login component:

 <template>
  <v-content>
    <v-container fluid fill-height>
      <v-layout align-center justify-center>
        <v-flex xs12 sm8 md4>
          <LoginForm></LoginForm>
        </v-flex>
      </v-layout>
    </v-container>
  </v-content>
</template>

<script>
import LoginForm from "../components/login/LoginForm";
import Logo from '~/components/Logo.vue'
import VuetifyLogo from '~/components/VuetifyLogo.vue'

export default {
  name: 'Index',
  components: {
    LoginForm,
    Logo,
    VuetifyLogo
  },
  data: () => ({
  }),
}
</script>
like image 262
Nícolas Teixeira Avatar asked Feb 11 '20 00:02

Nícolas Teixeira


2 Answers

Update June 4, 2021. Tested on Vuetify 2.5.3 and Google Chrome 90:

You can still use placeholder prop with one space in combination with persistent-placeholder prop.

...
<v-text-field
  label="Login"
  v-model="loginItem.login"
  placeholder=" "
  persistent-placeholder
  :rules="rules.login"
/>

Old answer. This solution stopped working starting from vuetify 2.4.0 (thanks @saike for the info):

As a simple workaround you could add placeholder prop with one space:

...
<v-text-field
  label="Login"
  v-model="loginItem.login"
  placeholder=" "
  :rules="rules.login"
></v-text-field>
...
<v-text-field
  label="Password"
  placeholder=" "
  v-model="loginItem.password"
  type="password"
  :rules="rules.password"
></v-text-field>
...

That's how it looks like when login/password was saved in your browser (in my case it's Google Chrome 80):

Autosaved

And with empty values:

enter image description here

like image 169
Alexander Shkirkov Avatar answered Jan 02 '23 01:01

Alexander Shkirkov


The solution that works for me is generating a random name attribute. With my solution I used uuid v4 method. If you rely on name then obviously this might not work for you unless you keep a map of names -> v4 output.

import { v4 } from 'uuid'
<v-text-field
    v-model="card"
    class="card-input"
    outlined
    :name="v4()"
    label="Credit Card Number"
    :rules="creditCardNumberRules"
    v-mask="[' ####  ####  ####  ####', ' ####  ####  #####  ###']"
/>
like image 43
Josh Avatar answered Jan 02 '23 02:01

Josh