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

    How to get standard error text when using q-input with Vuelidate?

    Framework
    3
    6
    3371
    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.
    • P
      paul last edited by

      I have following q-input:
      <q-input v-model=“form.amount” type=“number” stack-label=“Amount” @blur="$v.form.amount.$touch" :error="$v.form.amount.$error" />

      which has following vuelidate standard validation rules attached:
      validations: {
      form: {
      amount: { required, between: between(1, 999) },
      }

      The inputbox nicely colors red when the validation fails, but I can’t get the standard error text which I presume vuelidate generates like “the field amount is required”, "the value of amount must be between 1 and 999).

      Any idea.
      Warm regards
      paul.

      1 Reply Last reply Reply Quote 0
      • rstoenescu
        rstoenescu Admin last edited by

        Wrap with a QField. Look for examples in the docs.

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

          http://beta.quasar-framework.org/components/field.html#Validations-with-Vuelidate

          This snippet should fit your input:

          <q-field
            :error="$v.form.amount.$error" 
            error-label="The amount is required and must be between 1 and 999"
          >
            <q-input v-model=“form.amount” type=“number” stack-label=“Amount” @blur="$v.form.amount.$touch" :error="$v.form.amount.$error" />
          </q-field>
          
          P 1 Reply Last reply Reply Quote 0
          • P
            paul @a47ae last edited by paul

            @a47ae Thanks for the reply. Basically, a field can have multiple validators attached to it. So, I’m searching for a way to show the standard error message which goes directly with these standard validators and show them or show the first one that fails.
            So, in your example the error msg will always be “The amount is required and mustbe between 1 and 999” while the error could be related to another validator failing.

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

              I am not using Vuelidate, but another validator library (http://vee-validate.logaretm.com/) which generates these error messages for me.
              But from quickly scanning the docs Vuelidate does not do this.

              Instead, you could use computed properties to generate the message and bind this to error-label

              <template>
                <q-field
                :error="$v.form.amount.$error" 
                :error-label="amountError"
              >
                <q-input v-model=“form.amount” type=“number” stack-label=“Amount” @blur="$v.form.amount.$touch" :error="$v.form.amount.$error" />
              </q-field>
              </template>
              
              <script>
                export default {
                  computed: {
                    amountError () {
                      if (this.$v.form.amount.required) {
                        return 'The Amount field is required' 
                      } else if (this.$v.form.amount.between) {
                        return 'The Amount must be between 1 and 999'
                      } else {
                       return null
                      }
                    }
                  }
                }
              </script>
              

              This is a quick and dirty version, but you should be able to start from here. 🙂

              P 1 Reply Last reply Reply Quote 0
              • P
                paul @a47ae last edited by

                @a47ae Cool. That’s very useful info. Thanks you very much.

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