No More Posting New Topics!

If you have a question or an issue, please start a thread in our Github Discussions Forum.
This forum is closed for new threads/ topics.

Navigation

    Quasar Framework

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    Issue with vuelidate state not updating

    Help
    2
    6
    1133
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Y
      Ylec last edited by Ylec

      Hello, I have issue with vuelidate (0.7.4) integration with last version of Quasar.

      I added vuelidate in boot folder.

      My component :

      <template>
        <q-page class="flex flex-center">
          <div class="q-pa-md" style="max-width: 400px">
      
            <q-card class="q-pa-md">
              <q-form
                @submit="onSubmit"
                class="q-gutter-md"
              >
      
                {{$v.form.username}}
                <p v-if="error" class="q-pa-sm text-white rounded-borders bg-negative">{{ error }}</p>
                <q-input
                  filled
                  v-model.trim.lazy="form.username"
                  :disabled="loading"
                  label="Your login *"
                  hint="Nom d'utilisateur ou adresse e-mail"
                  :error="!this.$v.form.username.$error"
                  error-message="Required"
                >
                  <template v-slot:prepend>
                    <q-icon name="person"/>
                  </template>
                </q-input>
      
      
                <q-input
                  filled
                  type="password"
                  :disabled="loading"
                  v-model.trim="form.password"
                  label="Votre mot de passe *"
                  :error="!this.$v.form.password.$error"
                  error-message="Required"
                >
                  <template v-slot:prepend>
                    <q-icon name="vpn_key"/>
                  </template>
                </q-input>
      
                <div>
                  <q-btn type="submit" color="primary" :disabled="this.loading">
                    <q-spinner v-if="this.loading"></q-spinner>
                    Log in
                  </q-btn>
                </div>
              </q-form>
            </q-card>
      
          </div>
        </q-page>
      </template>
      
      <script>
        import {required} from 'vuelidate/lib/validators'
      
        export default {
          name: 'Login',
          data: function () {
            return {
              form: {
                username: '',
                password: ''
              },
              loading: false,
              error: ''
            }
          },
          validations: {
            form: {
              username: {required},
              password: {required}
            }
          },
      
          methods: {
            async onSubmit() {
             ....
            }
          }
        }
      </script>
      
      <style>
      </style>
      
      

      My issue is that all value from $v state are not update.
      model, $invalid and required are updated, but $error and $dirty are always false.

      Here is $v value when login field is empty :

      { 
      "required": false, 
      "$model": "",
      "$invalid": true, 
      "$dirty": false, 
      "$anyDirty": false, 
      "$error": false, 
      "$anyError": false, 
      "$pending": false, 
      "$params": { "required": { "type": "required" } }
      }
      

      Does anybody knows what is happening here ?
      Thanks.

      1 Reply Last reply Reply Quote 0
      • metalsadman
        metalsadman last edited by metalsadman

        Call this.$v.form.$touch() before submit. Or you can call it in one of the events on your inputs. You should refer to vuelidate docs too, they have many examples there.

        1 Reply Last reply Reply Quote 0
        • Y
          Ylec last edited by

          Thanks, it works that way, but in the vuelidate doc, about the $dirty property, it’s written that it is set automatically when writing to $model value.
          In my case, it’s not set automatically.

          1 Reply Last reply Reply Quote 0
          • metalsadman
            metalsadman last edited by metalsadman

            if so, then you should use the vuelidade model in your v-models, ie. <q-input v-model="$v.form.username.$model" ..,. one thing, you can’t call this in the template so in your :error prop it should be like :error="$v.form.password.$error".

            1 Reply Last reply Reply Quote 0
            • Y
              Ylec last edited by

              Damn, I feel dumb to not have read the documentation properly, and creating a post not related to Quasar at all…
              Thanks.

              1 Reply Last reply Reply Quote 0
              • metalsadman
                metalsadman last edited by metalsadman

                Well, it’s easy to miss stuff from the docs, but would be easier to review it over and over when you stumble upon an issue before hunting for answers outside of the official docs :), and there’s always google which most of the time faster than waiting for someone to reply.

                1 Reply Last reply Reply Quote 0
                • First post
                  Last post